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

Python IP geolocation script

These are two Python scripts I wrote to convert a GIGANTIC text file of over 100MiB in size (the current version is 152.735MiB) to an SQLite3 database to use for geolocation, and the script that ...
Ξένη Γήινος's user avatar
-1 votes
1 answer
67 views

Find the first value bigger than a threshold

This function takes two inputs: A is 2D (N,5) while B is 1D (N). It tries to find the smallest ...
Sanyou's user avatar
  • 3
3 votes
2 answers
126 views

Middle-outwards alternating iterator

I have a use-case where I want to iterate from the middle of an array outwards, so I generate a list of indices as follows: ...
Seanny123's user avatar
  • 1,527
1 vote
0 answers
75 views

"Sticky Note" App

The code below is a Sticky Note App. ...
Shraddha Shetty's user avatar
9 votes
3 answers
2k views

Repeatedly remove a substring quickly

I'm trying to solve the USACO problem Censoring (Bronze), which was the first problem for the 2015 February contest. My solution works for some test cases, but then times out for test cases 7-15. I ...
Kimi M's user avatar
  • 101
3 votes
1 answer
144 views

Hunting for the 100,001st prime in Rust

Most of my programming experience is in Python, but my first language was C, and I was intrigued by the combination which Rust offers: a streamlined syntax and no manual memory management, but with ...
Tom Hosker's user avatar
2 votes
1 answer
98 views

USACO Arithmetic Progression

The problem statement: An arithmetic progression is a sequence of the form a, a+b, a+2b, ..., a+nb where n=0, 1, 2, 3, ... . For this problem, a is a non-negative integer and b is a positive integer. ...
Michael Granger's user avatar
0 votes
2 answers
161 views

Python script that makes generalized Ulam spirals

This is a Python script I wrote to generate generalized Ulam spirals. I call the spirals generated by my code Ulamish spirals, they are one dimensional polylines that cross all two dimensional lattice ...
Ξένη Γήινος's user avatar
-2 votes
1 answer
136 views

Design an algorithm to predict words based on a skeleton from a given dictionary

The model I'm building first selects a secret word at random from a list. The model which uses an API then returns a row of underscores (space separated)—one for each letter in the secret word—and ...
driver's user avatar
  • 212
5 votes
3 answers
200 views

Fast complex absolute argmax in Cython

I'm thinking I implemented it optimally, but somehow it's much slower than what should be much slower, np.argmax(np.abs(x)). Where am I off? Code rationale & ...
OverLordGoldDragon's user avatar
5 votes
2 answers
732 views

Cleaning up a large python class for readability and becoming more pythonic/OO

I have a class that takes in two strings via the __init___ method and then does a bunch of string manipulation to return ...
metersk's user avatar
  • 389
4 votes
0 answers
67 views

Manage have-read and want-to-read books and series

I am building this program to keep track of the books I have read and the series I want to read, and I would like help on improving the user interface. ...
coolcoder613's user avatar
5 votes
2 answers
450 views

Optimizing a node search method given a 2-D spatial point

I have a tree-like structure called grid. I have designed it as a structured numpy array. Each element of grid is a tree-node. ...
matts's user avatar
  • 53
1 vote
2 answers
45 views

Transform the words in a Word document

This is a simple transform of a Word document to embolden the first half of each word. I used the python-docx module. The environment if needed was VS Code; for now ...
Vttrium's user avatar
  • 11
1 vote
3 answers
87 views

Python function Converting an integer to bins as per given interval

I am trying to convert an integer (num) to bins as per given interval. the bin size (intervals) are ...
Arun Kumar Khattri's user avatar
7 votes
2 answers
2k views

Guessing game in Python which uses a While Loop with 3 guesses

The following Python code is a guessing game in which players have to guess a number between 1 and 10. They only get 3 guesses, and the code will also display if the number is too high or too low, ...
Jason's user avatar
  • 71
2 votes
1 answer
137 views

Is this the right implementation for Linear Programming (puLP) on python?

I have created a LP function to help maximize a set of features. My first time playing with this library and also conducting LP. Variables: Number of features => X Number of Categories => Y ...
Kale 's user avatar
  • 33
1 vote
0 answers
27 views

Pandas to combine data files & add new calculated columns to result

I currently have the following python code that adds a few calculated columns to my consol file. Essentially it combines all the sales files into one combined DF and then adds 4 new sales columns with ...
Neo's user avatar
  • 11
8 votes
5 answers
1k views

Find out all the different files from two different paths efficiently in Windows (with Python)

Well, recently I'm working on a program which is able to sync files between different folders. However, as a fresh man, the algorithm I worte seems feasible, but looks really disgusting, and ...
Robert He's user avatar
3 votes
1 answer
101 views

Messy Sudoku solver

I have made a simple Sudoku solver in python and TKinter. However, I have used code from many different sources, so it is not neat. I can only write ugly code, so it is just about impossible for me to ...
Pazzel's user avatar
  • 33
4 votes
2 answers
351 views

Analyzing Product Photography Quality: Metrics Calculation -python

I am working on analyzing product photography data on the website and would like to gather feedback on my approach. The goal is to calculate various image metrics to assess the quality of product ...
sdave's user avatar
  • 143
4 votes
1 answer
589 views

Verifying Why Python Rust Module is Running Slow

I am working on converting some python code over to Rust, and I have come across a bit of a peculiarity in the way that my code is behaving. Namely, the module that I have written in Rust is much ...
peabody's user avatar
  • 143
0 votes
2 answers
107 views

Web scraping spider

I'm currently working on my first web scraping project and I need to scrape a lot of websites. With my current code it takes more than a day but for my project I need to scan the same websites every 5 ...
Max's user avatar
  • 17
0 votes
1 answer
133 views

Pythonic and mypy compatible way to map str to Enum

my goal is to have a user input a string that is checked to be valid - by defining a dict of allowed strings - and mapped to another string to be stored in a list. Another function is supposed to map ...
user2606240's user avatar
4 votes
3 answers
1k views

Python Enum Strategy Pattern

I have two behaviours: pulling or cloning a git repository. It started as an Enum, but then I had to switch over the enum all the time. I wanted to turn it into some kind of strategy pattern and ...
lukstru's user avatar
  • 958
1 vote
2 answers
54 views

Combination of three vocabulary sets

"Core", "advanced", "extra" are sets of vocabulary for those who study a foreign language. A user has to choose one, two or all three sets. I would like to get all ...
Kifsif's user avatar
  • 163
2 votes
1 answer
90 views

Password recognition with cryptography

Since I only just learnt about this, I wanted some advice on better practices I can use when it comes to cryptography. Still learning python and hoping I can get this 'hashing' and 'salting' thing in ...
Beginner's user avatar
  • 189
1 vote
1 answer
63 views

Using Pandas to group data based on name and see if column value is greater than or equal to values based on group names

As you'll see from the below code, I'm creating separate data frames of a much larger data frame, then updating a column for each one. What I'm doing is looking at the second column and checking to ...
jp207's user avatar
  • 173
2 votes
1 answer
96 views

Pomodoro Work Timer with GUI

My first actual code using GUI. Based off a class I took. Code criticism much appreciated. (I was all over the place with this one) Resources Picture: Sound: https://www.freesoundslibrary.com/success-...
Beginner's user avatar
  • 189
5 votes
3 answers
428 views

Python script to split overlapping ranges, version 4

This is the fourth iteration of a Python script I wrote that splits overlapping ranges, and this is the fastest version I have wrote so far, and also a version that works for all inputs. I have done ...
Ξένη Γήινος's user avatar
4 votes
4 answers
874 views

Lottery Analysis (Python Crash Course, exercise 9-15)

I was working on Python Crash Course, exercise 9-15: 'Lottery Analysis'. It took me a very long time to get it to work. The reason it took that long is I wanted to use my existing class from the ...
snapieee's user avatar
0 votes
1 answer
45 views

Locality Sensitive Hashing using Random Projection method

Can you review the following Python code? ...
user366312's user avatar
1 vote
1 answer
84 views

measure distance between two points in python

I'm working in a function that generates isochrones for a project of mine and I'm facing a bottleneck performing some distance calculations. Here is what I'm doing: ...
Franco's user avatar
  • 11
2 votes
1 answer
295 views

Model-View-Presenter (MVP) pattern implementation

To learn more about design patterns, particularly the Model-View-Presenter (MVP) pattern, I am currently creating a CLI weight tracker application in Python. I would like you to review the code to ...
J. Lo's user avatar
  • 53
1 vote
2 answers
46 views

Split Pandas dataset column based on values (suffixes: string operation)

In Python using Pandas, I am splitting a dataset column into 4 lists based on the suffix of the values. For the 3 suffixes I am using a list comprehension then for the 4th one, a set operation that ...
evilmandarine's user avatar
4 votes
1 answer
165 views

Blog site generator in python

Summary: This project is a simple static blog site generator written in python, utilizing pandoc to convert posts written in Markdown to HTML. It is essentially a follow up to my previous post: blog ...
766F6964's user avatar
  • 901
5 votes
1 answer
275 views

Identify distance degeneracies on square and hexagonal lattices

I have an interest in how the number of ways you can reach from the origin to a certain distance on both square and hexagonal lattices. If L is the square of the distance and integer pairs (i, j) are ...
uhoh's user avatar
  • 451
1 vote
0 answers
47 views

Python CLI tool - automatic mapping from models to parameters with Click

I was working on a small python CLI tool using the Click library for the first time and realized I was defining parameters and mappings from them to objects/classes in multiple places and anytime I ...
Coupcoup's user avatar
  • 1,067
5 votes
2 answers
747 views

Finding the first item in a python list which is big/small enough

Here is how I intend to do it: ...
sgt's user avatar
  • 53
-2 votes
2 answers
126 views

Applying the __add__ operator on all fields of a Python object

I have a class for which I want to overload __add__ to mean adding all fields between obj1 and ...
Alexis Drakopoulos's user avatar
3 votes
4 answers
1k views

Output a Python dictionary as a table with a custom format

I have a Python directory containing some str: int key-value pairs, and my goal is to display that data in a tabular format. I am unable to use the ...
David Gard's user avatar
1 vote
1 answer
56 views

Change unit-test structure to avoid try/except/finally clause

I have 10 or 20 tests with the same structure which I would like to improve. The test itself is nested within a try/except/finally clause to make sure that some of ...
Mathieu's user avatar
  • 211
0 votes
0 answers
67 views

Pygame Texture Ray Caster

Recently I have been attempting to develop a ray caster in python pygame. I managed to get it to work fairly efficiently when using basic colors, but when I altered the program to use textures instead,...
JohnSmith's user avatar
2 votes
1 answer
68 views

Generating Test Data with Python

Background: I'm a BI developer building a new dashboard for a client. They want to track performance for the week/month/year to date against the prior period. Unfortunately, I don't have direct access ...
DixieFlatline's user avatar
3 votes
1 answer
75 views

Simple Python MVC app for incrementing numbers using buttons

Intro: I am learning about the model view controller (MVC) architecture and I am looking for feedback from more experienced/knowledgeable people so I can check if my understanding is sound, and learn ...
dg0802's user avatar
  • 51
0 votes
2 answers
196 views

Printing the elements of a linked list [closed]

An absolute beginner here who is practising linked list problems in hackerrank. Stumbled upon this question which is categorised as easy. Given a pointer to the head node of the linked list, print ...
brucey's user avatar
  • 19
6 votes
2 answers
894 views

Script that tells you the amount of base required to neutralise acidic nootropic

Function Gives the mass needed of specific basic (pH above 7) substance in order to neutralise the pH of a specific acidic substance. ...
Nickotine's user avatar
  • 378
1 vote
0 answers
89 views

Python script that maps natural numbers to lattices in a spiral-like manner

This is a Python script that maps natural numbers to lattice points in a spiral like manner. It maps all natural numbers to all points with integer coordinates, and it produces a list of coordinates ...
Ξένη Γήινος's user avatar
2 votes
0 answers
230 views

YouTube downloader application with GUI in Python

I would appreciate a review of my Python script that interacts with the YouTube API and downloads videos or audio from YouTube URLs or playlists. The script uses the pytube library for downloading and ...
Paichiwo's user avatar
  • 121
1 vote
2 answers
1k views

Simple Connection Pool for SQLite in Python

When I talk to people regarding connection pooling in SQLite most of them always laugh and say "You don't know about SQLite", "It is not a client server DB, and only overhead in ...
Swastik's user avatar
  • 13