Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
4 votes
2 answers
199 views

Connecting MongoDB using Motor in FastAPI

What are the best practices for connecting to a database in FastAPI? To provide some context, I want to write code to connect to a MongoDB database using Motor. My idea is to create a single ...
Heber Alturria's user avatar
-2 votes
0 answers
40 views

Caching result of generator function [closed]

I want to cache the return values of a generator function. I did some research and found nothing without extra dependencies. I did come up with my own solution. Maybe that is good or not. Would ...
dvonessen's user avatar
2 votes
1 answer
76 views

A game where the player guesses the computer's number

I am fairly new to programming, and I recently finished part of one of my projects, a guessing game. The part I completed was the game mode where the player guesses the computer's number. I'm quite ...
ADAM WELLER-FAHY's user avatar
4 votes
1 answer
327 views

API Generator for Python [closed]

I'm currently working on my thesis to obtain a bachelor in software engineering, and i want to get some feedback from real developers of how useful this project can be in the real life. the project is ...
Hernandez Sinsel Jesus Emmanue's user avatar
1 vote
2 answers
79 views

Python - streaming file

I need to download and upload around 1000 files. The file is first downloaded from one webserver and then uploaded to another. My first approach was to save each file on disk and then upload - but as ...
John's user avatar
  • 241
-1 votes
0 answers
26 views

Unable to get names on a webpage [closed]

I have written some code to get the names on a webpage of car dealers at a postcode. But for some reason i am getting nothing. Not sure what i am doing wrong. As far as i can tell all my paths are ...
nevster's user avatar
  • 189
3 votes
2 answers
274 views

Python - Text-based game about an escape room

This is my first project, a short text-based game. Does this code follow common best practices? Here is the code for the class file: ...
codexploit's user avatar
2 votes
2 answers
63 views

Can I make my percolation in python function more efficient?

We've been tasked with finding out how many randomly distributed discs with radius = 1 it takes to form a chain of discs from the left side to the other of a square with side length = sqrt(n), and ...
Emilio's user avatar
  • 23
-1 votes
0 answers
29 views

Discriminator and Generator loss is constant in cGAN [closed]

I have a financial .csv dataset. After preprocessing, I converted it into a graph structure with nodes, edges, and labels. My plan is to apply Graph Attention Network (GAT) on the graph data. I ...
Girish's user avatar
  • 1
3 votes
5 answers
1k views

How do I speed up this simulation program

This is a program to solve a differential equation numerically using Euler method. As of now, it is very slow, and I need to run 10000 Monte Carlo simulations. The differential equation is called ...
Jonathan Wick's user avatar
1 vote
1 answer
64 views

FastAPI not full utilization

I have Django development in background for several years. Now I am practicing more framework this time is FastAPI. What program does: It is todo tasks with undo feature. I split the model into 2 ...
Sarit's user avatar
  • 113
3 votes
2 answers
64 views

Validating a web crawlers page visits with a decorator

I am writing a crawler that is going to end up in production and I was trying to come up with a way to validate its page visits. It scrapes asp.net pages so each scraping process involves a few ...
Gustavo Costa's user avatar
2 votes
1 answer
83 views

Semi-generic data loading utility class

The following implements a relatively generic and modular data loading utility. It loads images from a local storage given a lookup table. The data loader is parametrized via dependency injection to ...
lo tolmencre's user avatar
8 votes
3 answers
2k views

Bug Byte puzzle from Jane Street

This is a puzzle from Jane Street. Given this graph: Fill in the edge weights in the graph with the numbers 1 through 24, using each number exactly once. Labeled nodes provide some additional ...
Marc's user avatar
  • 5,604
2 votes
1 answer
87 views

Multithreaded sparse linear solver in Python

I would like to know if there are any multithreaded sparse linear solvers for LU decomposed sparse matrices. I want to increase the solving speed of a system like: ...
aqw's user avatar
  • 29
0 votes
2 answers
82 views

samba automounting script written in Python [closed]

My question is about the design of the program, if we could simplify the code logic in a or b function or remove, reuse, or create more functions. Also, another question I have is if it's ok to handle ...
Andres's user avatar
  • 3
5 votes
3 answers
809 views

code format and steps web scraping using beautiful soup

I've done simple web scraping and want to make sure all my steps are correct? Is it considered clean code? Is there a better way to use the multi-page scraping feature? ...
Lpython's user avatar
  • 51
1 vote
1 answer
115 views

Guess the number game with an easy and hard mode

I have started learning to program in Python. I watched a YouTube course for beginners creating the well known "guess the number" game. I have attempted to write an improved version of the ...
Enes's user avatar
  • 29
1 vote
2 answers
63 views

Using odd prime powers, my heuristic tries to solve instances of Exact 3 Cover in polytime, what can be done to optimize it?

By the way, a heuristic is not the same thing as a proven working algorithm that solves all input instances. It could either be experimental or be used to study intricacies in a problem. The purpose ...
The T's user avatar
  • 451
3 votes
1 answer
114 views

Collatz conjecture plots (python)

I have tried to improve my code with the suggestions I recieved in my old question about Collatz conjecture Here is the new code: ...
Lorenzo's user avatar
  • 157
2 votes
1 answer
163 views

Hackerrank "New Year chaos" solution - permute sequence by swapping adjacent terms

I was doing the Hackerrank "New Year chaos" problem. Here is the description: It is New Year's Day and people are in line for the Wonderland rollercoaster ride. Each person wears a sticker ...
user12138762's user avatar
1 vote
1 answer
44 views

Clique Connect: minimum spanning tree

Problem Statement You are given a weighted undirected graph G with N vertices, numbered 1 to N. Initially, G has no edges. You will perform M operations to add edges to G. The i-th operation (1≤i≤M) ...
user24714692's user avatar
1 vote
0 answers
64 views

Performance Tuning to enable answer for Project Euler #566 "Cake Icing Puzzle"

Related to this question I am still looking for a solution to Project Euler Problem 566 (see link for a nice simulation also): Adam plays the following game with his birthday cake. He cuts a piece ...
DuesserBaest's user avatar
3 votes
1 answer
61 views

Pytorch code running slow for Deep Q learning (Reinforcement Learning)

I'm a new student in reinforcement learning. Below is the code that I wrote for deep Q learning: ...
Jahid Chowdhury Choton's user avatar
2 votes
1 answer
90 views

Project Euler #566 "Cake Icing Puzzle" Performance Tuning

I am rather new to python and wanted to use Project Euler to learn more about it. The task can be seen here, so I will skip any description of my own: Project Euler Problem 566 (see Link for a nice ...
DuesserBaest's user avatar
4 votes
3 answers
651 views

Plotting Collatz conjecture values - Python

I am writing a program to display the behavior or certain seeds when you apply the Collatz conjecture algorithm to them. I would like to know what I should change and also if there is a way to see ...
Lorenzo's user avatar
  • 157
1 vote
1 answer
85 views

Blackjack optimization in python (Update)

A little while back, I made a post on blackjack using object oriented programming. I've begun running simulations under it, it runs fairly quickly but I know there is always improvements to be made. I ...
Joseph Beegle's user avatar
6 votes
2 answers
578 views

Advanced Python Grade Calculator

In this project, I've developed an Advanced Grade Calculator that not only calculates the average grade but also accounts for credit hours and predicts future performance based on historical grade ...
Shamp Phili's user avatar
2 votes
1 answer
80 views

"Flattening" a 2D STM image by subtracting an Nth order polynomial without typing out all the terms for each N?

I have some scanning tunneling microscopy (STM) topography images that I need to flatten. I have found that for some data I need a 4th order polynomial, but in other cases a lower order works better. ...
uhoh's user avatar
  • 473
6 votes
1 answer
311 views

Codeforces: D2. Counting Is Fun (Hard Version)

The code works okay for the following problem. Problem An array 𝑏 of 𝑚 non-negative integers is said to be good if all the elements of 𝑏 can be made equal to 0 using the following operation some (...
user24714692's user avatar
5 votes
2 answers
331 views

Coding challenge for mixing a string

Challenge at https://www.codewars.com/kata/5629db57620258aa9d000014/train/python Given two strings s1 and s2, we want to visualize how different the two strings are. We will only take into account ...
Vessel's user avatar
  • 133
6 votes
1 answer
89 views

Crossword game with python and flask

I recently finished my first major software project, aiming to provide an educational crossword product for my school assignment that can generate and display always-unique crosswords. I learned a bit ...
Tomas's user avatar
  • 63
4 votes
2 answers
391 views

Poker bets on Python

I'm writing poker for my bot in discord. So far I'm presenting an incomplete version of the project, which is only a betting system. The development took a lot of time, so I decided to ask for help. ...
Cat met's user avatar
  • 43
0 votes
1 answer
119 views

basic rock paper and scissors v2

I tried to implement what I understood from previous advices here. use more functions improve the logic of "play" allow wrong user input indent to 4 spaces and remove ...
Mah Neh's user avatar
  • 79
2 votes
3 answers
138 views

Solving the Towers of Hanoi problem in Python by using 3 stacks

I am attaching my code to solve the Hanoi problem. What do you think? Would you change something? I am attaching the instructions for solving the problem, does the code solve the question? In the ...
SHOVAL's user avatar
  • 51
3 votes
3 answers
848 views

Basic python rock papers scissors game (first code)

I'd just appreciate if anyone can suggest some incremental improvements that would help me to think better like a coder. Here is the very basic RPS (rock, paper, scissors). One thing I may next add is ...
Mah Neh's user avatar
  • 79
-2 votes
1 answer
34 views

fstab entry variable inside or outside function [closed]

So, I am working on a script that mounts smb shares. I have this function: ...
Andres's user avatar
  • 3
2 votes
1 answer
54 views

Flask web normalizer CSV app

I've created a Flask application that processes Excel files uploaded by users. The application reads specific data based on client-specific keywords and generates a CSV file which users can download. ...
Pointless's user avatar
2 votes
2 answers
121 views

BlackJack in python

I began creating blackjack in python; however, I'm looking to simulate it, so I'm thinking I'm going to need to optimize it so that I don't just leave my computer running for three hours waiting for ...
Joseph Beegle's user avatar
3 votes
2 answers
224 views

Tic-tac-toe OOP Minimax Algorithm

I wrote a module that I intend to use in my next tic-tac-toe project. All it is is a class that stores the boardstate along with some methods/properties. The biggest thing is the minimax alg. As shown ...
flakpm's user avatar
  • 55
1 vote
1 answer
139 views

Dial up some obscure stats for the Chutes and Ladders game

Years ago, I wrote some code in Perl for the Chutes and Ladders game. I re-wrote the code here in Python. The code simulates one player in a game to see how many spins of the dial are needed to win ...
toolic's user avatar
  • 3,516
14 votes
4 answers
2k views

Create a snail matrix

Statement: Create a script that, given an integer \$n\$, create a square matrix of dimensions \$n \times n\$ with the numbers from \$1\$ to \$n^2\$, arranged in a snail pattern. Example: ...
Dorian Turba's user avatar
6 votes
4 answers
427 views

Optimal Solution for the Four Divisors Problem on LeetCode

I recently encountered the Four Divisors problem on LeetCode and managed to achieve a 100% beat rate with my solution. I'd like to share it with you all and gather feedback on its effectiveness and ...
BrunoBarreto's user avatar
2 votes
3 answers
81 views

Arithmetic practice script in a tkinter window

I wrote a script that gives the user a quick arithmetic quiz and results using a tkinter window. I am very new to programming, and this is also my first time using <...
flakpm's user avatar
  • 55
7 votes
3 answers
999 views

Is this Python/Pygame that draws a maze well structured?

I'm not very confident about this piece of code I created, it basically takes a file like this: ## # ## ## # #B # # # ## ## ## A###### Then proceeds to ...
José Gomes's user avatar
2 votes
1 answer
58 views

Python sklearn rolling yearly validation

I am trying to implement a simple modelling pipeline with rolling c.v., making use of the TimeSeries split. The code is provided below with a working example dataset. (please don't pay too much ...
Lucas Morin's user avatar
4 votes
2 answers
320 views

Optimizing Multiple Subplot Visualization and Navigation in Matplotlib

I have implemented a class in Python using Matplotlib for visualizing multiple subplots along with navigation buttons to move between different subsets of data. Each subplot displays a contour plot ...
Cold Fire's user avatar
4 votes
2 answers
164 views

Matrix Factorisation class packaging methods for factorisation of explicit & implicit data matrices using Gradient Descent, SGD and ALS

Attached below, and also as this GitHub gist, is code for a Python class I wrote as part of a personal learning/portfolio project on collaborative-filtering recommender systems via matrix ...
Cosmic Fan's user avatar
-1 votes
2 answers
101 views

Breadth-first search [closed]

there are some problems in this code that I can't think of a solution. It does work for print(real_path,count) but the real thing I want is return real_path,count and for doing this I need to make the ...
tumr's user avatar
  • 53
5 votes
3 answers
309 views

Find highest number of swaps within a set of possible duty swaps with networkx and PuLP

With huge help from Stack Overflow, I have created code which takes possible swap matches with given weights as an input and outputs a set of matches which gives the highest weight with the highest ...
Oehoe's user avatar
  • 53

1
2 3 4 5
310