Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.

Filter by
Sorted by
Tagged with
0
votes
0answers
22 views

DOI name validation with pydantic

I'm trying to understand how to use pydantic for data parsing & validation. The idea I had in mind was following: I have a list of DOI names for which I need to collect metadata I could use ...
-2
votes
0answers
17 views

Implementation of a contour plot [Python]

I am trying to make a contour plot using meshgrid with Python. My dependent variable is not a direct function of the two, but I enter the values by hand. Consider the following example code: ...
1
vote
1answer
32 views

Separate an email address into its username and domain name

This is my first ever Python program and I wanted to get everyone's opinions on it. The goal of the program is to separate an email address into its username and domain name. ...
1
vote
3answers
57 views

“Digit Queries” CSES Solution giving TLE

I really need a more accurate way to size inf_string. This code works but gets exponentially more inefficient the bigger max(queries) is, and therefore just can't hold up to the gargantuan numbers ...
0
votes
0answers
7 views

scatter subplot for iris dataset

I'm new to data science. I wrote this script for plotting all different kinds of iris data set scatter plot. trying not to plot something with itself . how can I optimize my code ? ...
0
votes
1answer
24 views

High code complexity SonarLint

I am a beginner coder and SonarLint tells me code is too complex. I tried recursion, iterators, slicing but had not luck making this code any simpler. Can someone help me? ...
0
votes
0answers
14 views

Fast bruth force numpy array combination

I want to extract combinations of numpy arrays in that way: ...
0
votes
0answers
16 views

Bar chart - can we simplify?

I have a dataframe: ...
-1
votes
0answers
12 views

After removing text from file, how to remove empty lines from file using python [closed]

I am removing content from file and rewriting using python This is the initial script [Property file] username=admin pwd=admin host1=0.0.0.0 host2=1.1.1.1 I am ...
1
vote
1answer
26 views

Optimising Prefix Sum

I have a question: Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each the array element between two given indices, inclusive. Once all operations ...
0
votes
1answer
21 views

Python Back-end registration validation

I'm working on a personal project (Flask CRUD app) and I am currently building the user service. I am trying to use as less as libraries as possible (that's why I do not use WTF-forms for example, ...
0
votes
0answers
23 views

Optimize Yahoo Finance Code for Analysis

I am trying to analyze a number of companies using financial data I gathered from Yahoo Finance. I am also using the yfinance API to get some more details about the company using functions. Since I am ...
0
votes
0answers
34 views

Is there a better way to calculate joint probability?

After a long struggle, I've completed the Heredity project of "CS50's Introduction to Artificial Intelligence". However, I feel like my solution was not the most dignified way of doing it. ...
4
votes
1answer
45 views

Beginner python solution to CSES “Permutations”

I'm working through the CSES problem set as I learn to program, and this solution was accepted, but I'm not quite happy with it. I just know there's a faster way to check whether or not a solution's ...
0
votes
0answers
49 views

Python: Slow while inserting data to table [closed]

It is taking much more time to execute the script than expected. For just 1250 records, it is taking 20 plus minutes to loop and insert into the table. Please let us know if this is normal Below are ...
0
votes
0answers
20 views

Proper Python type-annotation for variable parameters signature of inherited method overloads

I have a CLI lib to automate batch operations on GitHub with many use cases: create issue, merge PR, delete branch... Since they all operate in a similar fashing regarding execution and output, I ...
1
vote
1answer
32 views

Populate database of web articles

What I have here is a relatively simple endpoint for a small site I'm making. Idea is to take: title content tags and create an entry in the database. It works properly. I threw this together as ...
-2
votes
1answer
23 views

Adding keys/values together [closed]

I'm using python 3.7 and I am using multiple dictionaries. Some of the keys are present in both dictionaries, some are not. Most of the values are numbers. ...
2
votes
1answer
32 views

Create a divisors list and identify primary numbers

I tackled a beginners' exercise: "asks the user for a number and then prints out a list of all the divisors of that number." The workflow I established is: input an integer number, say ...
4
votes
2answers
78 views

Retrieving top-level opening and closing sequences from a Python string

The problem I'm solving is a more complex version of pairing up opening and closing brackets. Instead of matching only on ([{}]), I additionally need to match ...
1
vote
0answers
7 views

Selenium Webscraper for Odd data analyses

I have written the following code to achieve the following: Regularly scrape all live matches on the betting site oddsportal.com Pull odds data into data frame Evaluate data frame for two odd ...
4
votes
2answers
52 views

Python beginner looking for feedback on simple dice game

Dice "Game" So, just started python a weeks time ago, so I'm looking for feedback/critique on things i can do to improve my code. I wrote a little user/pc dice rolling game. Any feedback at ...
2
votes
1answer
28 views

command-line binary/hex conversion program in python

I'm just learning the ropes to programming, so bear with me here. I wanted a simple command-line program to quickly convert decimal numbers into either binary or hexadecimal. This is what I came up ...
0
votes
1answer
15 views

Forming a dynamic dictionary based on searched key and values pair using RAW logic and not modules of python

I am trying to create a dictionary with a file containing text based on a matched pattern. Lines containing key_str should become keys and subsequent lines not matching key_str should become values ...
4
votes
3answers
244 views

use regex to separate a list of serial numbers into multiple lists with matched prefix

The question comes from How to separate a list of serial numbers into multiple lists with matched prefix? on Stack Overflow. Input: ...
2
votes
0answers
28 views

Covid Tracker + Notify people = Ideal for small coffee place or similar

This is my second project since I started with Python, this time I learned a little bit of SQL that is so useful and beautifully simple. Starting idea: Generate a program that will store information ...
1
vote
0answers
29 views
-3
votes
0answers
27 views

How could this web crawler built with pure Python be better written [closed]

I just found a Web Crawler very well made and built using basic python modules and I would like to improve it so the code does a similar thing but with less code but also using best practices and ...
1
vote
1answer
36 views

Performance issue in python- network creation based on the Euclidean distance with nested for loops is too slow

I want to create a network in which the links are formed based on a similarity metric defined as the Euclidean distance between the nodes. The distance is calculated using socio-demographic features ...
2
votes
0answers
15 views

git-user - Working on a shared local repository with multiple users made easier

I have recently been in a situation where multiple developers worked on a shared local git repository under the same Linux user1. As one can imagine, it can easily become a bit annoying not to commit ...
-1
votes
1answer
44 views

Finding longest word in a sentence

A problem from Coderbyte. Find the longest word in a sentence after removing the punctuations and if two or more words are of same length return the first word Below is my solution: ...
4
votes
2answers
77 views

Converting Integers to roman between 1 and 1000

Below is my code for the problem: ...
1
vote
1answer
60 views

decreasing solver speed

How can I decrease the time complexity and increase efficiency, without writing a new algorithm. My solution solves the majority of puzzles in a fast time, but for some difficult ones it can take over ...
1
vote
1answer
27 views

Python (Flask) - User registration system

I am working on a simple CRUD app as a personal project using Flask. I am currently working on the user service and I just finished the registration process. I am also trying to use as less as ...
-2
votes
0answers
21 views

Python /xed problems? [closed]

The code printed below is in Korean because I'm making a Korean text adventure ...
-4
votes
0answers
32 views

Python programming: [closed]

#Answer the following question without running the code. The procedure isMyNumber is used to hide a secret number (integer). It takes an integer x as a parameter and compares it to the secret number. ...
4
votes
2answers
240 views

Creating a database, a table within the database and inserting some values into it in one go

I've written a script which creates a new database, a table within the database, ...
1
vote
0answers
32 views

Asking for feedback, when utilizing Pandas, why is it better to use pandas.Series than lists data type?

I found out the hard way, when utilizing pandas is better to use pandas.Series than lists data type to manipulate data. Even if ...
3
votes
1answer
58 views

Python OOP - Web App (Flask) - User registration class?

I am working on a simple CRUD app as a personal project using Flask. I am currently working on the user blueprint and trying to use as less as libraries as I could and no ORM (for learning purposes). ...
2
votes
2answers
80 views

Downloading COVID data and uploading graphs

So this is a project I have been working on for the last few weeks. Just started learning Python. Started out with bash scripting and got the itch to learn more. Anyway code fetches covid-19 data from ...
-2
votes
0answers
27 views

Creating a 3D array from a dataframe and grouping said dataframe [closed]

I have a dataframe df where I have two particular columns of interest: "trip" and "stop#." Each trip has unequal number of stops (think of any ...
6
votes
3answers
1k views

Vigenère Cipher problem in competitive programming

I've just started doing programming problems. https://icpcarchive.ecs.baylor.edu/external/58/p5880.pdf The code below works fine, but my run time is 2.715 seconds and the time limit is 3 seconds. How ...
2
votes
1answer
41 views

Create file path and filename in JSON and send it to Discord

I have been working on a function which I call report. What it does is that whenever I call the report function. I can give it a ...
-1
votes
1answer
41 views

Improvement of the config file management in a project that manage simulation experiments [closed]

Improvement of the config file management I am working on a personal project for more than 6 months now, this project is composed of three distinct parts, simulation (wrapping a software), database ...
2
votes
1answer
40 views

Client-server application for logging running processes

My first client-server application. It's a simple Python script that gets a list of running processes from Server_1 and writes it to a datetime-named file on ...
0
votes
0answers
24 views

Reduce computing time of planning method (grid)

Has anyone an idea how to change the planning(self, sx, sy, gx, gy)-method to save computing time? I'm new to NumPy and don't know how to use it effectively yet, but I heard it could also be a good ...
6
votes
1answer
110 views

Entire discord bot

I've made a Discord bot, and (to my knowledge) the code is pretty good. However, I've mostly taught myself Python and discord.py (the discord library for Python), so I was wondering if there's any ...
2
votes
0answers
13 views

Assigning parallel workers to predict from keras model using concurrent.futures

I am working on a Reinforcement learning project, where I have to gather a lot of data using a TensorFlow model. During the data gathering, the weights of the model do not change. So, I am using ...
3
votes
2answers
102 views

How to speed up the code for LeetCode “Container with most water” task?

I'm trying to solve the LeetCode question where you need to find out the area of the container with the most water. I have created the solution that seems to work in my testing but it fails for being ...
0
votes
0answers
22 views

Faster way to open xarray file from zip folder stored on S3

So I want to open xarray file which is stored inside zip folder located on S3 bucket. And here's my attempt. ...

1
2 3 4 5
267