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
8
votes
1answer
152 views

Find all paths in a graph

My code does a DFS on the given graph and prints all possible paths for a given start and end node. My question is how can this be improved? Can some form of memoization be used here? There are cases ...
3
votes
2answers
30 views

Runge Kutta 2 Python ODE fluid flow

I am trying to solve a set of differential equations in x,y,z, I have made simple kutta 2 code in python before but not with 3 variables. I am not sure if what i have done is an acceptable way to ...
0
votes
0answers
24 views

Algorithm for efficient creation of submatrices from original matrix

I wrote this code to simply visualise what happens to an image when it gets put through repeated convolutional filters is a CNN. The code works fine and produces the expected result but the it is also ...
6
votes
2answers
701 views

Password Generator with injected password model

I'm getting started with Python and one of the beginner projects to learn the language was a password generator (one of the dozens already in CodeReview). I have a C# and JS background so I want to ...
9
votes
3answers
142 views

My Blackjack Game in Python

I am a beginner programmer ( just recently picked it up ). I just completed my first ever project, that is creating a Blackjack game in Python. I would like to know your opinions about it and how it ...
1
vote
1answer
39 views

Loss function in python is a bit cumbersome

This is my first post here. I seek to improve my way of writing Python and C++ code. I hope I can also contribute to others when I have increased my skill. Here is a python function I have for a ...
3
votes
1answer
117 views

Python script to parse XML file into Json

How are you doing? I have to make a script to parse an xml input file to a json file. I tried to do my best, but it will be nice if you could check it and help me to improve it. The idea is that I don'...
0
votes
1answer
48 views

addition of two list elementwise with abortion if condition satisfied python

I have a function that sums two arrays element-wise and stops if the sum at a certain index is greater strictly than 1. This function is called lot of times (15817145 times for a small simulation and ...
1
vote
1answer
52 views

Very slow Discord bot to play music

I have been writing a discord.py bot, running on replit.com. I gotten to the music bot part after finishing the queue part. My code is logically correct; however, the code is way too inefficient ...
1
vote
1answer
70 views

Robot OOP Class in Python

Hello everyone! Here is the thing. So I wanted at first to create Robot class, I want him to move around some board. Maybe 10x10 or something like that, then i wanted to invent a Robot fights class, I ...
2
votes
1answer
53 views

Chain of Responsibility design

I'm trying to design a chain of responsibility pattern. It slightly differ from traditional way when handler does only one action on a request, f.e. handles http response considering status code. But ...
0
votes
2answers
36 views

Relative Strength Index algorithm for stock values

This is an Relative Strength Index algorithm able to buy and sell stock based on values from basic stock CSVs. It works correctly and well, but I'm not sure if it can be better optimized as it ...
2
votes
0answers
28 views

AStar Implementation and Efficiency

This is my implementation of an AStar-like algorithm for maze solving. A quick summary of the problem I am trying to solve with my algorithm might be: A simple binary maze is given to you to solve, ...
3
votes
1answer
53 views

Verifying calibration process on IoT device, python script

I have an IoT device with accelerating and gyroscope sensors. before my device can be used it needs to be calibrated. Basically, it means that I do measures for XYZ axes and for the gyro movements and ...
1
vote
0answers
45 views

scan the RAM of a computer, displaying the services and executables

I wanted to write a program in python which it scans the RAM of a computer, by displaying the services and the executables. ...
4
votes
2answers
63 views

“Python AutoClicker” Part 2

I previously posted a question for codereview: Python Autoclicker And I received some great feedback and changes to do in the code. I have done many of the changes mentioned in the answers and here is ...
1
vote
1answer
42 views

Pandas merge a “%Y%M%D” date column with a “%H:%M:%S” time column

I have a dataframe with a column composed by date object and a column composed by time ...
7
votes
2answers
80 views

Multi-site backup utility with basic sanity checks

We have a large set of projects at work. It's very important we keep track of those and every so often we need to run a full back-up that's unrelated to the 'normal' back-ups IT is running (snapshots ...
3
votes
1answer
34 views

Finding the difference between the estimated value and the true value in a reward task

I have this function called error, which estimates value based on previous value and rewards in trials. The difference between the estimated value and true value is then calculated, giving the error. ...
6
votes
2answers
233 views

Docstring generator in Google type

Hello everyone! In this task I had to create docstring generator. I'm just wondering how you see this problem, I have to "take data" from the dictionary ...
3
votes
1answer
50 views

Python 3 IRCbot (library)

Just want you guys to review my python 3 IRC bot code, it is actually a fork of https://github.com/Orderchaos/LinuxAcademy-IRC-Bot You can see the source code at github I also have questions: I ...
2
votes
1answer
77 views

Main loop for a text-based Blackjack game

Is there any way to reduce this code? It repeats itself, but I cannot find any way to reduce it because it is only repeating inside one elif. Sorry I'm a beginner my code is quite bad It repeats here: ...
4
votes
0answers
38 views

Subclass of Python's multiprocessing.Pool which allows progress reporting

For context, the whole of the project code can be found here. This question was created specifically for the progress.py file. The goal behind it is to allow ...
5
votes
2answers
108 views

Simple number guessing game in python

The problem is to ask the user to guess a number between 1 to 100 and compare it with a random number of that range. If user guessed number is lesser/greater than the random number print "too low&...
2
votes
1answer
33 views

Multi-core OpenCV denoising

I have ~40,000 JPEG images from the Kaggle melanoma classification competition. I created the following functions to denoise the images: ...
4
votes
1answer
51 views

Calculate probability that knight does not attempt to leave chessboard after at most k random moves (LeetCode #688)

I'm learning competitive programming and came across this question on LeetCode : 688. Knight Probability in Chessboard On an n x n chessboard, a knight starts at the cell (row, column) and attempts ...
4
votes
1answer
57 views

Is my breadth-first search function any good? (Python demo included!)

I am learning Python and I wrote a functional breadth-first search algorithm which I wanted to be as general as possible. I wrote some code to draw a grid and visually show the path found. My code ...
7
votes
1answer
483 views

Generate combinations of a given sequence without recursion

Given an array of unique numbers find the combinations Doing a shallow copy in the code to avoid changes to the passed obj by reference This has a run time of \$O(n \times \text{#ofcombinations})\$ - ...
7
votes
1answer
133 views

A beginner's first Tic Tac Toe implementation

I've been teaching myself Python and decided to make a Tic Tac Toe game for a bit of practice. Any criticisms or pointers are welcome! ...
0
votes
3answers
89 views

Finding unique top sums from multiple lists

My question arises from this post on MSE where I have provided an answer to solve the question : There are multiple lists given. The number of lists is arbitrary. Each list contains numbers and is ...
1
vote
1answer
23 views

Filtering data from an exisiting table using psycopg2+sqlalchemy

I am using psycopg2 & sqlalchemy to connect to a database and extract information from a table as follows: ...
1
vote
1answer
40 views

Correcting coordinates of an image with polynomial root in python

I want to optimize this for loop for correcting coordinates of an image, it takes too long which is not suited for my system. I have done some profiling, the numpy roots is taking most of the time (...
3
votes
1answer
32 views

Managing configs to use scripts on different computers

I have some python scripts to run on different computers. To avoid struggles with different paths and filenames I made specific config-files (DConfig, AConfig and MConfig) and another script that ...
2
votes
1answer
77 views

Pizza ordering system

Is there any room for improvements in this code. I am new to programming (python3), learning and practicing functions related to arguments recently. ...
4
votes
0answers
25 views

Process Injector using ctypes and the Windows API

To get some practice with the Windows API and ctypes, I decided to write a program capable of injecting and running shellcode inside of another specified process. ...
1
vote
0answers
78 views

Generating Unique Subsets using Bitmasking

Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets. Link to the judge: LINK Note: Each subset should be sorted. Example 1: ...
4
votes
0answers
33 views

PyQt load images in background process

I am building an application that needs to load 100-200 images (really only limited by performance) and display them to the user in a sort of gallery. A good analogy would simply be Google Images. In ...
1
vote
1answer
44 views

Python Prime Search Slower Optimization

I have these 2 version of code. Both are looking for all primes under a certain ceiling value. The first is testing against the set of all odd numbers. The second in testing against the set of all 6k-...
4
votes
3answers
87 views

Converting hex to binary in the form of string

This code returns a string of binary in 4-digit forms for a given hex in the form of string ...
0
votes
0answers
29 views

Keras: Using Autoencoders for prediction

I have a dataset which I divided into two sections horizontally. Column A of first section is the input variable and Column A of second section is the target variable. I am trying to build a Denoising ...
3
votes
0answers
26 views

Logical next step in Django newsfeed web app

I'm hoping to get feedback on my current code from someone more experienced in Django, and in the concepts I'm trying to implement. Let me preface by saying that I am a novice to Django. This is my ...
9
votes
3answers
2k views

A password generator

This a small project for a beginner, it basically generate symbols digits letters depending on the user input I want to make the code better and learn from my mistakes. ...
0
votes
1answer
137 views

Encryption/Decryption algorithm #3

This is a follow up question to Encryption/Decryption algorithm #2 and Encryption/Decryption algorithm. In my last question, in @Reinderien's answer, he added this line ...
2
votes
1answer
57 views

PySimpleGUI app to monitor cluster CPU load

As a way to learn PySimpleGUI, and eventually tkinter, I re-implemented a computing cluster CPU load monitor I wrote long ago. I'm looking for any feedback on whether it's well-written, but in ...
2
votes
1answer
38 views

Query the github api and filter the last 1000 commits which include and exclude certain words from the top 3 repositories in a given organization

This code should query the github api and filter, out of the last 1000 commits, which ones include and exclude certain words from the top 3 repositories in a given organization. For example, I could ...
3
votes
1answer
102 views

Tic Tac Toe in Python 3.x

I made Tic Tac Toe in Python. Standard code review, please tell me ways to improve. I am very new to Python, so please do not criticize very roundabout ways. Thanks. ...
2
votes
1answer
113 views

Encryption/Decryption algorithm #2

This is a follow-up question to this one. I have tried to implement all the recommended things in the answers (except commenting, and not being OS specific). Again, if you see anything that needs ...
3
votes
2answers
27 views

PySpark SCD Type 1

I am using PySpark in Azure DataBricks to try to create a SCD Type 1. I would like to know if this is an efficient way of doing this? Here is my SQL table: ...
2
votes
1answer
46 views

Return list of tuples of date ranges

I have a start and end date. I would like to return a list of tuples, which have the start and end dates of each month. ...