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 vote
0 answers
10 views

Is using setup functions for commands, events, and tasks a good pattern for structuring a Discord.py bot?

I'm refactoring on a Discord bot using discord.py and I've structured my project as follows: ...
Hofbr's user avatar
  • 331
0 votes
0 answers
19 views

How to optimize recursive multi-step forecasting in Python

I am working on a machine learning project for hourly sales forecasting. I need to make 7-day ahead sales predictions. My model (XGBoost) uses lag sales from 24 hours ago as one of the inputs, to be ...
taha khamis's user avatar
8 votes
7 answers
591 views

Rudimentary black jack game implementation

I started the 100 Days of Code: The Complete Python Bootcamp about a week ago. I finished day 11, and I wrote a rudimentary blackjack game. I'm just looking for some advise on how I did. Am I showing ...
Wazeewa's user avatar
  • 81
0 votes
1 answer
34 views

Graph Neural Network (GNN) (2)

This is an implementation of a graph neural network. Edges are represented by an egde-list. ...
user366312's user avatar
0 votes
1 answer
74 views

Graph Neural Network (GNN) (1)

The given datasets are graph data structure that represents social interactions. The nodes will be represented as People{node_id, edge, gender, occupation} and the ...
user366312's user avatar
2 votes
1 answer
183 views

Neural network text classifier

I wrote a simple NN text classifier to help me quickly sort through the new daily submissions to the arXiv. It downloads the new submissions, processings their titles and abstracts, trains a NN on ...
Gabriel's user avatar
  • 597
2 votes
1 answer
42 views

Fast API endpoint handlers

I'm not so experienced at developing Fast API apps. As I program in different languages, I often get confused as how things are done in a python way. I have this piece of code, and I would like to ...
Alejo Villores's user avatar
0 votes
1 answer
41 views

Feature-subset-selection using autoencoder [closed]

The following listing performs feature-subset-selection (not feature extraction) using an autoencoder. My aim is to select the best features from the 1000+ available features in the given dataset. I ...
user366312's user avatar
5 votes
2 answers
365 views

Cost sharing application in Python

I am very new to Python (yes, I know it's been around a long time). This is my first working just-for-fun project to see if I could do something in Python. I know the UI layout is rather ugly and ...
Zack E's user avatar
  • 593
1 vote
1 answer
41 views

Send a QNetworkRequest with a parameter

I want to send multiple QNetworkRequests in Python 3.12 that each downloads one image from a server, using a single callback function. To be able to distinguish ...
Neph's user avatar
  • 113
9 votes
1 answer
863 views

Typical password generator in Python

Password generators are extremely popular on CodeReview with beginners to both coding in general and Python in particular, for a number of reasons: They're (seemingly) easy to implement They offer an ...
6 votes
3 answers
1k views

Implementation of Euler-Maruyama numerical solver

I am trying to write a python implementation of Euler-Maruyama and Milstein schemes for numerically solving stochastic differential equations. The pseudo-code for the algorithms is in the Wikipedia ...
Quasar's user avatar
  • 397
3 votes
2 answers
89 views

SEO Page Analysis Tool built in Python and Django

Objective: Develop an SEO analysis tool, for a website built in Django, that allows users to input a URL and receive an SEO report containing information about the page's optimization strengths and ...
user3605767's user avatar
0 votes
1 answer
62 views

Replace iterrow loops in pandas matrices with something else to shorten the running time

This post is modified from this one: https://codereview.stackexchange.com/posts/292885/edit (Alternatives to iterrow loops in python pandas dataframes). I have a piece of code to calculate price ...
Laura's user avatar
  • 61
5 votes
2 answers
633 views

Alternatives to iterrow loops in python pandas dataframes

I have a piece of code to calculate price sensitivity based on the product and its rating. Below is the original data set with product type, reported year, customer’s rating, price per unit, and ...
Laura's user avatar
  • 61
2 votes
1 answer
119 views

Time Series Forecasting

I'm currently working on a project involving time series analysis and have written the following code for the train-test split section. I'm particularly concerned about the correctness of the ...
user avatar
-3 votes
1 answer
75 views

Initializing an object using a staticmethod

I've an object that looks like this, and users have been populating the attributes post-initialization, e.g. ...
alvas's user avatar
  • 699
0 votes
2 answers
54 views

Feature subset selection using neural network

This listing selects the best features from the 1011 available columns in a given dataset. The first three columns are dropped because they are useless data. The dataset is huge. So, they were read in ...
user366312's user avatar
8 votes
2 answers
1k views

Beginner level password generator optimization

I've been learning python for a few days now, and I programmed this password generator after today's lesson (following the 100 days of code on udemy course). This code works like it should and gives ...
PSapola's user avatar
  • 83
4 votes
2 answers
148 views

Excel sheet manipulation program

I'm very new to programming, and I'm hoping I can get feedback on the code I wrote - anything is helpful - what to split into different files (right now 1 large file), perhaps a way to break up the <...
Owlhunter1's user avatar
5 votes
3 answers
909 views

Optimizing Pi Estimation Code

I'm trying to write a program in Python that estimates pi, but to get a more accurate estimation in a feasible amount of time, I want to make it faster. I'm using a method that estimates the area of ...
Rhys Bradshaw's user avatar
2 votes
3 answers
149 views

Python Program Automatically Changing Mac Wallpaper to Nasa's Astronomy Picture of the Day

...
Astrovis's user avatar
  • 121
2 votes
3 answers
694 views

Capture multiple errors before raising an exception

I have a scenario where I need to store values from some environment variables (names of which I cannot control). My first run at this was pretty basic, however this is not usable as an exception ...
David Gard's user avatar
6 votes
8 answers
1k views

Reversing vowels in a string

Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper ...
user avatar
5 votes
1 answer
81 views

Backend-snippet of a full-stack web application for creating, viewing, and registering for events

The backstory (you can skip this if you want to) This code stems from a project that I had to do for a presentation for a university class around November 2023. The task was the following: Create a ...
JupperTV's user avatar
0 votes
0 answers
41 views

Scrapy Spider - Code Audit and Optimization Suggestions

I've written a Scrapy spider to scrape product details from a specific website. The spider is designed to navigate through various pages, locate specific products, and gather detailed information ...
I DON'T KNOW's user avatar
3 votes
2 answers
133 views

Check for key in dictionary without magic value comparison

I'm using pydantic in a project to check file formatting for an object, as well as pylint for linting. Whenever I read a file with an invalid format, I want to raise an exception with a descriptive ...
BobVitorBob's user avatar
2 votes
1 answer
57 views

Scrapy Spider for fetching product data from multiple pages of a website

I have written a Scrapy spider to scrape product data from a website. The spider navigates through multiple pages to reach a specific product and extracts details such as the product name, price, ...
I DON'T KNOW's user avatar
4 votes
2 answers
681 views

What is the best way to set a class value to a variable in Python if it exists in a dictionary?

I have this code which sets values in a location class from values from JSON data. ...
Asher Ross's user avatar
3 votes
1 answer
89 views

Build a dictionary from a string by the extraction of data from all the pairs <TAG|VAL> contained inside the string and clean string from TAGs

I have written code to manage a string and retrieve from it a dictionary which must contain pairs key-value dependent from the string. To be more clear I'll show ...
User051209's user avatar
1 vote
1 answer
37 views

Delete duplicates from SQL database with Python and reset ID's

I tried to create a peice of code that helps me remove duplicates from my sql database and reset the ID's as well. I am not sure that it's error proof. ...
Giannis Tsakas's user avatar
7 votes
2 answers
148 views

"Polite" internet connectivity check on separate thread

I wrote this class that checks for internet connectivity on a background thread. Targeting Python 3.10. It has two main design goals: Minimize the time get_state() ...
Jason C's user avatar
  • 451
4 votes
1 answer
136 views

String art program in Python using PyTorch

...
flakpm's user avatar
  • 97
2 votes
2 answers
133 views

"Element Fusion" game where 2048 meets Chemistry

I've developed "Element Fusion," a PyGame-based game inspired by 2048 but using chemical elements. I'm seeking feedback on: Gameplay mechanics Code structure and efficiency PyGame ...
Amirhossein Rezaei's user avatar
5 votes
3 answers
855 views

Project Euler 127 - abc-hits

Problem (Rephrased from here): The radical of \$n\$, \$rad(n)\$, is the product of distinct prime factors of \$n\$. For example, \$504 = 2^3 × 3^2 × 7\$, so \$rad(504) = 2 × 3 × 7 = 42\$. We shall ...
Nadav Nevo's user avatar
3 votes
1 answer
96 views

matplotlib color N-slope-normalization

Based from the source code of the TwoSlopeNorm color normalization of matplotlib, I tried to implement a more general normalization that can handle any number of &...
mocquin's user avatar
  • 133
1 vote
1 answer
92 views

AsyncSession + Transactional decorator for SQLAlchemy repository class

I have a prototype pattern for leasing sessions to a PostgreSQL database and would like a review. I took inspiration from this project on github. ...
Bob's user avatar
  • 63
0 votes
1 answer
73 views

Take photographs using simulated cameras that share a lock

I'm new to threading in Python. I want to use it to speed up taking images on my lab computer. I have the following dummy code: ...
AccidentalTaylorExpansion's user avatar
7 votes
5 answers
3k views

Check if license plate number is formatted correctly

I'm just learning Python and am looking for some feedback on some of the code exercises I've completed and do work. In particular, what would make them more Pythonic, or more closely align with ...
Th1s0neGuy's user avatar
2 votes
2 answers
66 views

Implementing load and save operations for a text editor (proof of concept)

I have a text editor in C does not give much thought to losing data whilst overwriting the original file to save new progress. To circumvent this problem, and make the process robust, I ended up with ...
Harith's user avatar
  • 9,462
3 votes
3 answers
98 views

Determinant of matrix Python

This is an addition of my previous question Python matrix class. I've added a determinant function using Laplace expansion to my Matrix class. What I am looking for specifically is how 3x3 matrices ...
Linny's user avatar
  • 10.3k
2 votes
1 answer
37 views

Maintain a log containing values if certain conditions are met

I'm trying to capture profits and set a stop loss in my trading strategy. I want the stop loss to be set daily based on the past data and if the current price, i.e., price for the date falls below the ...
driver's user avatar
  • 232
2 votes
1 answer
41 views

Optimal Extraction of Longest Sorted Sequence from Individually Sorted Bucket Arrays Without Repetitions

Consider a bucket array containing sorted and/or empty buckets, and the goal is to extract the longest possible sequence in sorted order, under the following conditions: Only one element in each ...
M.A.'s user avatar
  • 121
1 vote
1 answer
269 views

Rules-engine to be improved/simplified for Efficiency (performance), Extensibility and Maintenance?

This is a simple implementation of a rules engine. I am really hating the very long MATCH/CASE function. I am wondering what kind of Design Patterns could be used there to make this code more ...
user avatar
11 votes
1 answer
891 views

a not-so optimized, not-so simple brainfuck source-to-source compiler to assembly (fasm) written in python that automatically compile using fasm

first time writing this source-to-source (i think) compiler, not an expert, not a pro, not an advanced person, just a beginner, I don't think this is cross platform. ...
user avatar
4 votes
2 answers
656 views

Python script to auto change profiles in MSI Afterburner

I am coming from a stackoverflow question and after I hit a brick wall I tried to find a work around. I only found this working for me and work around the ...
Giannis Tsakas's user avatar
0 votes
1 answer
52 views

Low Validation and Test Accuracy with Random Forest on ECG signals

I'm working on a project involving ECG data classification using a Random Forest model. Unfortunately, my model's performance is significantly lower than expected, and I'm struggling to understand why....
MEJRI Rawaa's user avatar
5 votes
0 answers
83 views

Optimizing SymPy Implementation of prime factorization in form of QUBO

I'm trying to reproduce a paper on Prime Factorization. This paper converts the problem into a QUBO form, which then we can map it to an Ising Minimizer. I've basically done everything and I've ...
Amirhossein Rezaei's user avatar
4 votes
3 answers
308 views

Calculation of centrifugal liquid propellant injectors

There is this code in which the calculation of the centrifugal nozzle of a liquid rocket engine is performed. All basic calculations take place in the Injector ...
DYNAMIC AEROSPACE's user avatar
2 votes
1 answer
126 views

Check that a string is a palindrome using Cython

I am trying to check if a string is a palindrome in cython. Here is the code I am using: ...
John's user avatar
  • 309

1
2 3 4 5
311