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
1
vote
1answer
33 views

Count the frequency of n-grams in a random Wikipedia corpus

This code counts the frequency of n-grams in a random Wikipedia corpus, as of now, it downloads everything, than performs all the counting. In your opinion is there a way to perform downloading and ...
1
vote
0answers
13 views

Unit tests coverage of functools extension library

A few days ago I requested a review of my functools extension library. Since I did not have any unit tests for it, I started writing some for the revised version of this library. I'd like some ...
2
votes
0answers
18 views

Variable Grid Size Tic Tac Toe

Tic-Tac-Toe from scratch. Code Ugliness check before I implement the win-condition and maybe get set in to bad habits. Questions: As implemented: Better to pass board between functions or set as a ...
1
vote
1answer
537 views

Python multi-threaded kubernetes watcher

My program (which eventually will be containerised) should be able to do the following: continuously listening for deployment and daemonsets in kubernetes (2 threads) collect info needed (like ...
3
votes
2answers
57 views

Implementation of a Parser for Analysis Description Language

I have created a script for parsing ADL and the code looks like below. Example ADL file I am looking for suggestions to divide the code in multiple methods and make it more readable. Thanks ...
2
votes
2answers
127 views

Extracting data from dict and processing it

Consider the following ...
0
votes
0answers
36 views

Comparing 2 CSV files by ID and printing the output as CSV [closed]

I want to compare two CSV files in Python. They both have the same columns, first column is the key variable (ID). One of the CSVs has more rows than the other. My goal is to print the differences in ...
0
votes
0answers
32 views

Efficient way to build random undirected graphs without self loops given total number of graph nodes and associated node degree

I wrote an algorithm to build 1000 different random graphs given number of nodes and node degree. Node degree is maintained between the random graphs. I am building these random graphs to input to a ...
2
votes
1answer
78 views

My code creates a soundboard that can assign a sound to a key on a keyboard while listening to keyboard strokes in parallel

My code works but I am looking for an efficient way to implement the idea with out having to repeat the same code block inside the function Recin() (record Input function is stated in the code) in ...
2
votes
1answer
55 views

benchmarking requests to localhost

I am writing a benchmarking tool from scratch in Python. However I can't get the performance of other benchmarking tools like wrk or ...
3
votes
2answers
1k views

Decrease the number of lines of code needed to create a list and verify one value

What can I do to reduce the number of steps until I get to the final code result? Is it possible or is this the way with the least number of lines of code? ...
3
votes
2answers
2k views

William Fractal technical indicator implementation

I'm really new to both Python, data analysis and Panda and for gathering a bit of familiarity with this components and trying to replicate a trading strategy I'm creating a function that give me the ...
0
votes
1answer
657 views

Making a File explorer with Python tkinter

I am making a simple file explorer with tkinter Python. This is the file repository on github. I know that this is pretty much long code and it took that much time to write but i have somehow added ...
4
votes
2answers
491 views

Rock, Paper Scissors game using Python

This is a simple rock, paper scissors game I attempted as part of the Automate the Boring Stuff with Python course on Udemy. The scope of the game is for the user to enter a valid input, the system ...
-1
votes
1answer
75 views

Python: select n of each type from ordered dict

I have a for loop that contains multiple if -conditions. The speed of this function is not critical for my application at the moment but I'd like to learn and have a few tips how to optimize my code ...
2
votes
1answer
60 views

How do you efficiently calculate YTD values in a pandas dataframe?

I implemented the following code to calculate the YTD sum in Pandas: ...
5
votes
2answers
1k views

Check for matching symbols

The following code is a working solution for the balanced parentheses problem. I'm really just wondering about coding style here when it comes to separating out related if-statements. When there are ...
2
votes
1answer
30 views

SMTP emailing library

Some time ago, I implemented an emailing library to simplify sending emails for several web applications and daemons. As usual, I am interested in improving my code. ...
6
votes
1answer
92 views

Implementation of Singly Linked List in Python

I am learning basic data structures in Python. I'm not confident enough if my implementations are OK or I miss any corner cases. So please check my code for Singly Linked List and Let me know where I ...
2
votes
2answers
64 views

Periodic Table of Elements (Python-tkinter)

This is a code that generates the periodic table where each element is represented as a button and info about the element is produced when that specific button is pressed. I wanted to make this code ...
1
vote
3answers
58 views

Send email to a list of recipients

I wrote code to automate sending emails using smtp in Python. Below is my code I've written. However, I think there might be a simpler way (simplified code)....could you please review and give me ...
2
votes
0answers
80 views

Can we make a worse automatic card shuffling machine?

So I've been droodling on a blackjack project, and one of the issues we need to solve is how to shuffle the cards. I've implemented a method that simulates hand shuffling (E.g split the shoe (either 2,...
14
votes
4answers
3k views

Split a restaurant bill, including tip

Just looking for a little feedback on the below tip calculator I've coded rounding the output to nearest 2 decimal places. Just wondered if it was readable and code friendly? ...
12
votes
3answers
7k views

Find total number of phone numbers formed by the movement of Knight and Bishop on keypad

I recently took a test on HackerRank, and submitted my answer for the following question. I passed all the test cases but company told me that the answer is not efficient, and they are not moving ...
3
votes
2answers
59 views

Cleaning a game logs list to find the frequent action triplets and the busy user

I have these game logs which I need to clean, process and find the frequency of game actions. These game actions should be a triplet. In the below given list, ...
4
votes
2answers
86 views

Rotating a matrix clockwise by one element without any libraries (Python 3.9)

The question is as follows: Rotate an NxN matrix clockwise by one element and display the new matrix. For example, if ...
6
votes
4answers
864 views

Clean up Python function with too many if/else statements

I have a working function with too many if/else statements (pylint). The code works but it's not good. I try to improve it but I have some tunnelvision. Can someone ...
6
votes
1answer
274 views

A Python-program that makes successive API-calls

I wrote some code to make calls to a public API. The code is correct as required as usual. My goal is to make the code as self-explanatory, maintainable and robust as possible. I also tried to make ...
3
votes
1answer
38 views

Collatz conjecture with plots

I have an assignment where I write a Collatz Conjecture program for a series of starting values from 1 to N and make two plots: number of iterations vs starting value and computed numbers vs starting ...
2
votes
1answer
41 views

Decorator for forward type hint resolution

Background I frequently develop ORM libraries using the peewee framework. On one particularly large ORM library, representing a proprietary data format, I have a lot of coupled ORM models representing ...
2
votes
0answers
29 views

Python: Random forest code optimization

I've been working on random forest algorithm for classification with roulette selection to find best splits. I came up with this homebrew based on this article https://machinelearningmastery.com/...
1
vote
0answers
36 views

Django User Model to authenticate using email address and password

This is my second Django project for an actual client and I want some review on one of my important models. This model will be responsible for authenticating users using their E-Mail Addresses and ...
-2
votes
0answers
24 views

zero values in dataframe - python [closed]

hey everyone I have a project to do and I will be glad to receive your help the dataframe I am working on is relatively large from Kaggel, it has 250 columns and 22000 rows, the data are from ...
2
votes
2answers
182 views

Find month with minimum net price change

Question: The interns at Amazon were asked to review the company's stock value over a period. Given the stock prices of n months, the net price change for the \$i^{...
5
votes
4answers
179 views

Create a little adventure world

I have just recently picked up coding and am trying to improve my coding. I've written this bit of code to create a little adventure world. I haven't completed the code, everything runs how I want it ...
1
vote
0answers
24 views

Looking for Correct Code Structure for FastAPI and Celery

I have a FastAPI app that uses Celery and depends on DB transactions. I'm a little confused as to where the DB transaction should occur--Whether it should be run inside the Celery task definition, or ...
0
votes
2answers
371 views

Interview: Drug Analyzer class

the introduction is this: You are a member of a biotechnology programming team that is responsible for creating a system for lab technicians, which will assist them with drug analysis. Your goal is ...
3
votes
2answers
228 views

List comprehension : Add new element in a list

I have a list and I want to made some manipulation on it. This my list : ...
1
vote
1answer
67 views

Slicing multi index DataFrame into JSON object

I have a MultiIndex pd.DataFrame that I generated from a .txt that is forecast model data. ...
1
vote
0answers
25 views

Pandas rolling evaluation

I want to perform some calculations over rolling periods of a pandas DataFrame and to abstract all this in a dedicated class. The job of the class below is simply, given backward and forward looking ...
0
votes
1answer
17 views

Flask-SQLAlchemy achieve 1 to many relationship that backfills parent when child is updated

Currently I have two tables Plan (plans) and User (users) and there is a foreign key constraint on users which references plans.id When I create a new user I want to assign a plan to that user via ...
1
vote
3answers
59 views

Python: generates Rolling date in reverse manner up to N number

This is my below code which accepts the date in specific format and generates the N number of rolling date which consists the first and last date of each month in reverse manner. ...
5
votes
1answer
346 views

Simple IP address subnet calculator

In this task I had to create simple IP address / subnet calculator in Python. I'm just wondering how you see this problem. There is my code: ...
7
votes
2answers
476 views

Hangman game in Python with nine possible words

I'm relatively new to Python, and I've been using the language for about a month. I set out to do the Hangman game. I would like to know if there are things to improve in the code of the program I ...
1
vote
1answer
56 views

Speed performance of sqlite3 queries looped in python

I have a table data stored in a database ships.db, the data are informations of tracked ships hourly. The table data looks like ...
1
vote
1answer
69 views

Better way to create a contingency table with pandas for film genres from a Film DataFrame

From a public dataset available on film rating I created a contingency table as follow. Honestly I don't like all these "for-loops" I think the quality of the code can be definitely improved ...
1
vote
1answer
45 views

Scan and Output ACLs to Excel in Python

I am working to solve an issue that my company is currently having, We have an extremely large share drive that is over 20 years old. There are so many security groups attached to some of these folder ...
2
votes
4answers
75 views

The user-facing part of the code base, using Python's argparse package

This question is a sequel to one I asked the other day. The previous question examined the core of my repo; this one examines the user-facing part. If you're curious to see what the repo as a whole is ...
0
votes
2answers
119 views

for loop Optimization

I have a sample Json as mentioned below ...
8
votes
3answers
346 views

Implementing a efficient Infix to Postfix using Shunting-yard algorithm

I was trying to implement an efficient (in terms of size of code (such as using one liners) and time and memory-efficient) of Infix to Postfix in python without the use of any external modules i.e ...

1
2 3 4 5
286