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
1 answer
68 views

Clear the temp folder with Python script

I am addicted to cleaning the %temp% folder, so I went ahead and tried with pyautogui at first by making it click ...
Giannis Tsakas's user avatar
8 votes
1 answer
501 views

Battleship vs. computer with Python

I am still pretty new to Python. After spending time on Code Wars and copying a handful of projects from Al Sweigart's Big Book of Small Python Projects, I wanted to build something completely from ...
Jessica Monnier's user avatar
8 votes
5 answers
1k views

Python matrix class

To prepare for my studies in linear algebra, I've decided to write a simple matrix class. This is the initial program, with functions to find the determinant and decomposition(s) to follow. I wanted ...
Linny's user avatar
  • 10.3k
0 votes
1 answer
46 views

Optimize for compute/timespace - substring matching STD pk / sk format

BUSINESS CASE For users of my application I need to manage a granular list of grants. I'm using an aws dynamodb backend with lite Single Table Design (STD) strategies. A common syntax for STD keys ...
Jamie Marshall's user avatar
0 votes
2 answers
42 views

Slicing or Extended unpacking [closed]

I have a MQTT topic: topic = "namespace/group_id/message_type/edge_node_id/device_id" I want to get the first node and the rest of the topic in a ...
Dorian Turba's user avatar
5 votes
2 answers
165 views

Python script to change monitor refresh rate

I recently overclocked my monitor and I am trying to create a script to just click and do the work for me so whenever I want to change my refresh rate I dont have to open windows settings. I think ...
Giannis Tsakas's user avatar
2 votes
2 answers
157 views

Find the join of two set partitions

Two partitions of a set have a greatest lower bound (meet) and a least upper bound (join). See here: Meets and joins in the lattice of partitions (Math SE) The meet is easy to calculate. I am trying ...
Watchduck's user avatar
  • 150
3 votes
1 answer
66 views

Number of partitions of (a,b) into k distinct parts which sum up to (a,b)

Problem set This is somewhat a generalization of the famous partition of integer n into k parts. Given two integers ...
linuxbeginner's user avatar
2 votes
1 answer
222 views

Python using generators with Excelwriter - Performance

I'm looking to understand if my code has an obvious blockage or performance pain point that will cause it to operate slower or use more memory than it should. The current Excelfile i am processing ...
sayth's user avatar
  • 131
3 votes
1 answer
268 views

Transferring dataframe columns into dataframe rows

I have the following data: ...
mahmoud988's user avatar
3 votes
1 answer
107 views

Benchmark for loop and deque/map/methodcaller

While discussing with some colleagues, one argued that a for loop over a list of objects to call a method is a bad practice because it has bad performance compared ...
Dorian Turba's user avatar
4 votes
2 answers
286 views

Simple size difference measuring tool

Simple tool I wrote in an hour or two (I'm not very fast, but I eventually get there - also for the "spending 6 hours to save 6 seconds" meme). Would've written this in shellscript given ...
404 Name Not Found's user avatar
4 votes
1 answer
63 views

Array Math to Calculate Ice Thickness -- Need Help Simplifying

I posted this on Stack but since it's working code, it was suggested I post it here. I wrote this code to calculate ice thickness using the following equation from Stephenson, 2011. It's a daily ...
emmahaggerty's user avatar
12 votes
4 answers
3k views

Python secrets command-line tool

I'm building a command-line tool that lets you use Python's secrets module. Here are some commands you can run with this tool: ...
code writer 3000's user avatar
10 votes
2 answers
1k views

A simple Python class designed to facilitate investment portfolio analysis

Background In an attempt to learn a bit more about investing and economics, I've begun writing a simple historical portfolio analysis tool in Python. The ...
IntegerEuler's user avatar
4 votes
2 answers
218 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
2 answers
133 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
339 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
95 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
3 votes
2 answers
295 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
77 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
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
70 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
70 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
88 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
132 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
87 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
822 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
121 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
71 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
119 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
184 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
2 votes
1 answer
69 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
3 votes
1 answer
152 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
81 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
101 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
668 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
92 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
607 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
85 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
328 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
338 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
107 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 ...
tomasvana10's user avatar
4 votes
2 answers
398 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
123 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
145 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
863 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
36 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
63 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