Skip to main content

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 votes
0 answers
32 views

Python Simple ECS Implementation [closed]

I have developed a very simple Python ECS implementation as a module, and would love some feedback on the code. GitHub repository is here The module is designed to be as beginner-friendly and as ...
Rich. T.'s user avatar
9 votes
3 answers
2k views

Solver for Wordle puzzle

After a success with the Jumble puzzle solver, I am doing a Wordle puzzle solver. I know many other Wordle solvers have been posted, yet this is my original version, which emphasizes list ...
inyoot's user avatar
  • 337
0 votes
0 answers
58 views

Element-wise natural logarithm of large array

Let X be a numpy.array of np.float32 with shape (100,100,100,100). I'm computing the variable lX with the following formula <...
manifold's user avatar
  • 121
3 votes
2 answers
735 views

Retrieval-Augmented Generation from text files

Context: I'm a complete newbie trying to get good at structuring my code. I'm aware that I'm supposed to do my own research with docs, but I don't know what specific docs I should be reading for this ...
Shades's user avatar
  • 41
6 votes
2 answers
421 views

Get orientation of a contour according to the smallest side

Context: Based on the code we can find here, an API to control to control Niryo's robots pyniryo/vision/image_functions:l120. Return orientation of a contour according to the smallest side in order ...
Dorian Turba's user avatar
2 votes
0 answers
79 views

backward induction algorithm computation

Is there a way to significantly speed-up this code? I'm solving a dynamic programming model using a backward induction algorithm. A crucial step is to calculate the current-period value function (VF), ...
manifold's user avatar
  • 121
9 votes
3 answers
1k views

Command Line Hangman game

I've completed a Hangman game in Python and was wondering about the formatting of this code. There were several functions that I switched around while making this, and there were several times where I ...
HeavenlyPanda's user avatar
9 votes
2 answers
312 views

Simple Node.js version manager v2

As a followup to my previous version, I decided to try make this more cross-platform. I considered several languages: C++ is pretty cross platform, Rust is gaining popularity (and the language used by ...
404 Name Not Found's user avatar
5 votes
2 answers
178 views

LeetCode Number 416: Partition Equal Subset Sum

Problem: MLE I am confused as to why the LeetCode judge reports Memory Limit Exceeded when my solution looks close to the editorial solution. I not too familiar with ...
user430243's user avatar
8 votes
4 answers
1k views

Python Exception Monitor

I have built a data pipeline in Python (3.12). It typically processes hundreds of thousands of files and runs for several days. A particular pipeline function calls external web APIs that sometimes ...
farhanhubble's user avatar
4 votes
3 answers
153 views

Function to calculate energy where all parameters must be positive

I have a function which requires all parameters to be positive: ...
Idieh's user avatar
  • 73
3 votes
1 answer
105 views

Time series prediction by LSTM model

I have a collection of TEC data. My data sample for example: day1, day2, day3, day4. Case1: I have the following task to do: Training by the consecutive 3 days to predict the each 4th day. Each day ...
S. M.'s user avatar
  • 123
1 vote
0 answers
99 views

Runtime function overloading / dynamic dispatch for Python (2nd revision)

Second revision of the original post: Function overloading / dynamic dispatch for Python TL;DR: Improved version of this library[^1] based on previous reviews and criticism. It provides runtime ...
HernanATN's user avatar
  • 379
7 votes
5 answers
1k views

Prime number finder below the limit specified

Is this an optimal solution? I doubt it is. Can someone please critique my code? ...
FirstTimer's user avatar
2 votes
0 answers
137 views

How to make this arbitrary precision π calculator using Machin-like formula run faster?

Two days ago (or yesterday depending on your timezone) was π-day. So I thought it was a good day to calculate π. I used Machin-like formula to calculate π, in homage of William Shanks, who calculated ...
Ξένη Γήινος's user avatar
6 votes
3 answers
393 views

Function which returns arithmetic expression based on an operator

For the following code, I have trouble improving it. I need to write a function getExpression(level, operator) which has one integer parameter representing a level ...
nathan007's user avatar
4 votes
1 answer
63 views

IBM File Processing and PDF Conversion App Using PyQt6 and FPDF

I am trying to convert a 111MB TEXT file to PDF quickly. I'm currently using the FPDF library, and large files take about 40 minutes to process. The text file is an IBM carriage control (ANSI) file ...
cessy's user avatar
  • 41
6 votes
2 answers
146 views

Pydantic model <-> neomodel OGM (neo4j) <-> python dict converter

I've written a converter between pydantic models of arbitrary complexity (thus, with submodels, nulls, lists) and neomodel models (library for ...
Max Azatian's user avatar
1 vote
2 answers
122 views

Implementation of my multidict in Python

I need a code review for my implementation of my multidict in Python. I'm not sure that my method below is implemented the best way: ...
OlRay9497's user avatar
4 votes
3 answers
329 views

numpy array/item handling functions

Recently I have been using numpy arrays, which have great utility via their broadcasting methods. I am attempting to write a useful public facing library, and this ...
Konchog's user avatar
  • 237
5 votes
6 answers
2k views

Bubble sort with 10 random numbers

I want to make a bubble sorting algorithm of 10 random (non-repeating) numbers from 0-50. I changed many aspects of it while making it and finally got it to work, but I would like to see if there's ...
asuno__'s user avatar
  • 61
4 votes
3 answers
247 views

Calculation of consumed resources by subprocess

I've created a script that executes arbitrary user code in Python, written in a .py file, and returns execution result (contents of stdout, stderr, exec code) + ...
Max Azatian's user avatar
6 votes
1 answer
871 views

Python function that deeply "freezes" an object

I implemented a function that gets an object and returns its immutable counterpart. If the object contains another mutable object at any level, it freezes it too. Is my code is good and/or can it be ...
Marco Sulla's user avatar
9 votes
2 answers
242 views

Blackjack game for assignment

I’m a first-year IT student, and I’ve completed a working Blackjack game in Python as part of an assignment. I’d love to get some feedback on my code structure, readability, and comments to improve my ...
Goose's user avatar
  • 91
1 vote
1 answer
101 views

Convolutional LSTM

I write code about convolutional LSTM, but I am not sure if mine is good enough. Is anyone interested in giving a look at my code? ...
mufei luo's user avatar
7 votes
4 answers
942 views

Project Euler #54: class for poker hands

I'm working right now on Project Euler problem 54, and I figured that this was the perfect opportunity to try to work with classes. This is my first time, so I'm sure that there are a lot of style, ...
Brais Romero's user avatar
7 votes
1 answer
233 views

Connect Four GUI with various board sizes and extra options

I've created a Connect Four game implementation, where I'm mostly interested in improving the GUI design. While not a software engineer by trade, I aim to create practical tools for my colleagues. ...
Mast's user avatar
  • 13.7k
-2 votes
1 answer
80 views

Intersect two arrays in python

I have two unidimensional numpy arrays in python, gs and ni. I want to intersect them but preserving the order in gs. When they have high cardinality this operation becomes so costly. Is there any ...
phyAlph's user avatar
8 votes
2 answers
920 views

2D block game like Minecraft

I have been working on a 2D block game. I like the progress I am making, but I would like to improve the performance and the overall quality of the code. The code and textures are stored in my GitHub ...
coder's user avatar
  • 241
5 votes
2 answers
83 views

Filipino Sign Language Recognition System Using MediaPipe & TensorFlow

I am working on a sign language recognition system that processes pre-recorded video datasets to extract hand gesture features for AI training. I am using MediaPipe, OpenCV, and TensorFlow to extract ...
Juwan Carlos Casuco's user avatar
6 votes
3 answers
241 views

GitHub Label Management with GraphQL, Requests, and Loguru

I've developed a Python script that automates the management of GitHub labels. It utilizes both the GitHub GraphQL API (to fetch label data) and the REST API (to update, delete, and merge labels). The ...
kiaora's user avatar
  • 141
2 votes
1 answer
55 views

Descriptor with cache depending on the update of another attribute

Python 3.11 here. I have created a descriptor that caches the value of the decorated method while the watched attribute has not changed. It can be used like so: ...
FTG's user avatar
  • 195
5 votes
1 answer
88 views

Find food related words in German: Seeking Feedback on Concurrency and Code Organization

I'm developing a pipeline that processes unknown ingredient data from the OpenFoodFacts API. The goal is to find valid German words that are not yet in their taxonomy. The tool performs the following ...
kiaora's user avatar
  • 141
2 votes
2 answers
75 views

Finding partial match table

I am trying to write code that creates a partial match table given a list. The following seems to produce the correct outputs, but it looks quite clunky to me. In particular, it feels strange to me to ...
Idieh's user avatar
  • 73
3 votes
2 answers
129 views

Running yolov to detect class on many files in-memory accumulate RAM on Google Colab T4 GPU

I have thousands of files and I am detecting with YOLOV some classes on them with my own model file. My files are inside a zip file. I must usually extracting json files which have vector data, then ...
Khaled's user avatar
  • 349
6 votes
2 answers
245 views

(HackerRank) Project Euler+ #250: 250250

Link to problem: linkNumber of solvers: 27 out of 844Solve rate (per person): 3.199%Success rate (over all submissions): 1.78% Project Euler+ on HackerRank is basically supposed to be a generalization ...
CrSb0001's user avatar
  • 499
7 votes
2 answers
111 views

A hatchling hook plugin to compile gettext po file at build time

Context General The Python Packaging Authority (PyPA) provides a framework to easily build and install packages from a source project. It works nicely for Python code and text files. I chose to use ...
Serge Ballesta's user avatar
7 votes
4 answers
1k views

LeetCode 977: Squares of a sorted array, maintaining non-decreasing order

I tried solving the LeetCode question like many others, trying to incorporate the O(n) time complexity requirement. Squares of a Sorted Array Given an integer array ...
Littlejacob2603's user avatar
9 votes
3 answers
574 views

Parsing SFV files to extract and store the hashes

Similar to the class for the RAR file, now a class to extract and store the hashes from SFV files. Though this was considerably easier, there has been some code reorganisation: there is now an ...
viuser's user avatar
  • 473
7 votes
1 answer
91 views

Pygame self-made sprite loader

I just wanted to put this out here and see what people think and potential improvements I could make. I've been learning spritesheets in pygame as I was really scared to use them as I thought they ...
ThisQRequiresASpecialist's user avatar
5 votes
1 answer
357 views

Trying Out DDD : How to enforce data integrity and immutability

I've been transitioning from type-safe programming languages like Dart and Java to Python, and I'm trying to enforce Domain-Driven Design (DDD) principles in a language that naturally leans towards ...
koussay issaoui's user avatar
4 votes
1 answer
52 views

sqlalchemy and alembic integration in FastAPI

I am building a fastAPI + sqlalchemy + alembic + docker-compose reusable template. Full source code: https://github.com/mascai/fastapi_template (commit 77ce7f2) I would appreciate pull-requests =) The ...
mascai's user avatar
  • 459
7 votes
2 answers
811 views

Numerical cellular automaton way of simulating water, fire or smoke

I have made up some evolutionary rules for a type of cellular automaton that uses numbers instead of the more common binary black or white cells. Rules in English: Takes place on a square grid that ...
R1s1ble's user avatar
  • 171
9 votes
3 answers
953 views

Getting information about a RAR file's content

The first lines of the rarpath module (see here for context, the rest is not used here): ...
viuser's user avatar
  • 473
7 votes
2 answers
243 views

Two-Step Linear Equation Solver with Input Validation and Formatting

This code defines a function to solve two-step linear equations of the form coefficient * variable + constant = solution. It prompts the user for the coefficient, ...
LMays's user avatar
  • 335
5 votes
2 answers
1k views

Function overloading / dynamic dispatch for Python

UPDATE: Second revision on separate post. Runtime function overloading / dynamic dispatch for Python (2nd revision) When I first started using Python I had a rough time dealing with some of it's ...
HernanATN's user avatar
  • 379
5 votes
2 answers
199 views

Sorting file names of a RAR split archive (v3 and v5)

This simple task of sorting a list of related RAR files of a split archive turned out to be more cumbersome than expected, since there are two versions of the RAR naming scheme, v3 and v5. v3 is like ...
viuser's user avatar
  • 473
5 votes
5 answers
3k views

Fast XOR of multiple integers

I need the bitwise XOR (exclusive-OR) of a list of integers (a function that is to ^ as sum is to ...
Watchduck's user avatar
  • 230
1 vote
1 answer
111 views

Database design using Closure Table for tagging system

I created these database tables with the inspiration in NjDevPro github repository. The design uses Closure Table for implementation of hierarchical tagging system in ...
xralf's user avatar
  • 37
11 votes
4 answers
2k views

Leetcode 93: Restore IP Addresses

(Source: Leetcode 93: Restore IP Addresses [Medium])(Topics: [String] [Backtracking]) The problem is as follows: Definition: A valid IP address is defined to consist of exactly four integers ...
CrSb0001's user avatar
  • 499

1
2 3 4 5
311

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant