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
0 votes
1 answer
29 views

yet another number of islands

i learn python and i am at beginner level in python TL`DR i did NOT read the other questions concerning this topic since i try to learn python and therefore need to do the same stoopid errors others ...
Martin Frank's user avatar
  • 2,714
2 votes
1 answer
39 views

Avoid code duplication of loop in Python's if statement and isinstance

I have a script - generator that accepts a file name or file object and a list of search words as input. The generator searches through the lines of the file and returns only those lines (the whole ...
zaelcovsky's user avatar
7 votes
2 answers
959 views

Faster chess engine in python (with move ordering algorithm?)

I, an amateur coder, have been trying to code a chess engine with python as part of a larger research project. I started by following this tutorial (turns out creator of said tutorial has a github of ...
pjq42's user avatar
  • 171
-1 votes
0 answers
15 views

Python scripting in Blender to do repetitive job namely modifiers [closed]

I am trying to run shrinkwrap and then remesh modifier repeatedly but not working. It seems to me there is a infinite loop ...
Fatih Hamırcu's user avatar
3 votes
2 answers
215 views

Time Format Conversion Utility

The code defines a Python script for converting time between 12-hour and 24-hour formats. Review Goals: Is the code idiomatic? (Am I using any outdated practices or functions?) Is there a simpler way ...
Harith's user avatar
  • 1,231
3 votes
3 answers
143 views

Python script to answer Rosalind test 2 (sum of two squares)

The test: https://rosalind.info/problems/ini2/ Problem Given: Two positive integers a and b, each less than 1000. Return: The integer corresponding to the square of the hypotenuse of the right ...
K Y's user avatar
  • 33
2 votes
1 answer
40 views

Emoji busy spinner for a textual bot that run lengthy async jobs and need to provide feedback

This is a small python API to be able to display a busy spinner using emojis for a textual bot that run lengthy async jobs without access to a percentage of completion and need to provide feedback so ...
Pierre.Sassoulas's user avatar
1 vote
0 answers
45 views

Convolution to reduce popcorn noise in black and white video

I have a black & white video as a tensor with the shape [Time, Width, Height] with popcorn noise and I would like to reduce the noise by naively convolving along the time dimension. Using a ...
Seanny123's user avatar
  • 1,517
7 votes
3 answers
2k views

Python program to properly format North American phone numbers

I made this program to properly format a North American phone number. If its a 10-digit phone number (9999999999) it adds a 1 in the beginning and adds in dashes (1-999-999-9999). If its 11 digits (...
Kovy Jacob's user avatar
1 vote
1 answer
45 views

Find all combinations of two companies grouped by the projects they are tendering for

I am working on the task to get all possible combinations (pairs) of ID's (companies) which participated in one bid and create a new data frame with ID_1, ID_2, matching parameter (tender ID). I have ...
Vasya_Ch's user avatar
0 votes
0 answers
32 views

How to read key value in JSON output without using index [closed]

Here is a sample JSON output myJSON: ...
Patrick Hennessey's user avatar
2 votes
0 answers
52 views

Python tic-tac-toe using tkinter

I recently made this tic-tac-toe program using tkinter, but I am quite new to tkinter, so I would be grateful for tips on how to improve the program. (Note that the actual tic-tac-toe logic is being ...
sbottingota's user avatar
3 votes
1 answer
78 views

Expirable LRU cache

The requirements are: evict any expired items find the items with the lowest priority and evict the least recently used one Any feedback would be appreciated. ...
random_letter's user avatar
6 votes
3 answers
438 views

Implementing a --assume-yes/--assume-no command line flag to affect a `input()` based `confirm()` function

I have a Python command line application that needs to ask the user for confirmation at some point. I want to add a --assume-yes/...
Lucas's user avatar
  • 161
0 votes
0 answers
45 views

Keras Tuner Subclass for Time Series Cross-Validation

Custom Keras Tuner with Time Series Cross-Validation I have written my own subclass of the default Keras tuner Tune class. Objective: I needed a way to incorporate ...
Furkan Öztürk's user avatar
1 vote
0 answers
35 views

Implementing Simulated Annealing to the Travelling Salesman Problem ; plotting a graph of temperature(x axis) and cost on y axis ; animating using cv2

...
PuzzleheadedSoup-98's user avatar
0 votes
1 answer
123 views

Leetcode: 2327. Number of People Aware of a Secret

On day 1, one person discovers a secret. You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the ...
jason's user avatar
  • 1
3 votes
1 answer
106 views

Highly flexible tic-tac-toe terminal game in python

I have created a two-file tic-tac-toe game, with board.py containing most of the internal workings of the playing board. I intended to have ...
norway-yv's user avatar
  • 141
1 vote
1 answer
100 views

Order of values in dfs and bfs

Let's consider a matrix of integers m: [[1,2,3] [4,5,6] [7,8,9]] Which represents a graph: ...
Gameplay's user avatar
  • 161
3 votes
1 answer
125 views

Combo Matching in a digital implementation of Reiner Knizia's 'Schotten Totten'

I'm implementing Reiner Knizia's card game 'Schotten Totten' in Python. It's a card game for two players, where you compete to claim boundary stones between you and your opponent by forming poker-like ...
Jan van Wijk's user avatar
1 vote
0 answers
39 views

A server side for a Premier League score guessing app

So I'm writing a Premier League score prediction app with Python, Flask and SQLalchemy and have almost finished the server side of it. I realised that no one has ever looked at my code and there could ...
Adam's user avatar
  • 11
1 vote
0 answers
47 views

Combined or separate data-cleaning routine

I am a junior data engineer that have 3 years of experience with Python. I write a lot of Python code for my job and I came up with this question I can't solve by my own. I don't have the chance to ...
Izem's user avatar
  • 11
8 votes
3 answers
2k views

Algorithm "sort except zero"

Task: Sort the integers in sequence in sequence. But the position of zeros should not be changed. Input: List of integers (int). Output: List or another Iterable (tuple, generator, iterator) of ...
Глеб's user avatar
  • 183
2 votes
2 answers
299 views

Simple calculator in python using tkinter

I just learned Python and Tkinter and I've just made a simple calculator using Tkinter for a small project at my school. It can do addition, subtraction, multiplication and division. I think that my ...
justANewbie's user avatar
1 vote
1 answer
67 views

Getting one company from two tables [closed]

Currently I'm working with fastapi, sqlalchemy to connect to multiple databases. It checks params to ensure it has company_name, ...
g3tl0st's user avatar
  • 111
0 votes
1 answer
28 views

Change the appearance of a log graph with two x axes

I would like to improve the overall look and feel of the two log graphs generated by the Python code below. The first graph represents the optimized methods while the second graph represents the ...
Ruan's user avatar
  • 101
5 votes
1 answer
74 views

Bank account class simulator with possible exception

I'm a newbie to python object oriented programming, Unfortunately in all the ways, Classes that I write turn into a true mess. I'd be glad if someone would be able to point me some of my mistakes. <...
KhodeNima's user avatar
3 votes
1 answer
69 views

Scraping the Divar.ir

I've wrote a code to scrape the Divar, which is an equivalent of Ebay in Iran. I have a few questions: Am I doing the error handling and logging ok? Is there a better way to optimize this code? (note ...
Amirhossein Rezaei's user avatar
1 vote
1 answer
83 views

CPU emulator written in python (Adjustable Microcode!)

I've designed and implemented a CPU architecture in one day. Of key architectural details: Processor is supposed to support updatable microcode, Architecture extensions and Is designed to be ...
ToAskOrNotToAsk's user avatar
0 votes
0 answers
30 views

Running a neural network backwards

I've read this paper where they basically run a network backwards. And decided to try. Luckily, many useful functions are implemented already in pytorch. The main idea is this: Write a convnet Write ...
Minsky's user avatar
  • 239
4 votes
1 answer
58 views

Improving readability of semi-nested classes for loading data of separate runs of a joint testing campaign

A bit of background: Most often I am analysing data (mostly timeseries) of mechanical machine conditions (vibrations, temperatures...) that were acquired in different 'runs'. All runs were acquired ...
Jorre Goossens's user avatar
3 votes
1 answer
48 views

Remove duplication from WebVTT subtitles

I want to perform statistical analysis and index subtitles that are stored in the WebVTT (Web Video Text Tracks) format. Before I can do that I need to remove duplicated text since each cue can ...
A Dark Divided Gem's user avatar
2 votes
1 answer
63 views

Use row data from a database to find rows in dataframes that match and use data to generate a separate dataframe

I have a DataFrame (database_df) that contains the general record with the IDs that are the same team in each of the lines, containing these values I need to find ...
Digital Farmer's user avatar
1 vote
1 answer
60 views

Algorithm for Conway's Game of Life in potentially infinite grid in Python

I implemented a program for computing Conway's Game of Life iterations in Python starting from an initial grid configuration given as input. It is intended to handle arbitrarily large grids. I tried ...
frix's user avatar
  • 357
6 votes
2 answers
988 views

File Organiser in Python

main.py The "main.py" script is a Python program designed to organize files within a specified directory based on their file extensions. It enhances file ...
I_throw_but_dont_catch's user avatar
4 votes
1 answer
100 views

Cellular Automata Python Class

I've been working on creating a simple Class for a Cellular Automata. It generates a grid of NxM dimensions populated by Cell objects - Pretty straightforward class to save the state of the cell-. It ...
Athansya's user avatar
4 votes
2 answers
134 views

Making a dice game as my first Python project!

I just started my programming lessons in school today and I decided to start learning more at home. This is my first day and I know the basics of if conditions, <...
Ekwa's user avatar
  • 41
4 votes
2 answers
123 views

NumPy script to convert BGR to HSL and back

This is a NumPy script that converts BGR arrays to HSL arrays and back, without using OpenCV. Input and output values are arrays of 3 dimensions with values ranging from 0 to 1, the shape of the ...
Ξένη Γήινος's user avatar
3 votes
3 answers
169 views

Increment a large integer represented as array of digits

This problem can be found at LeetCode. Since I was studying idiomatic or 'pythonic' code in my language today, I decided to take the most 'pythonic' approach and challenged myself to do this in one ...
KhodeNima's user avatar
1 vote
2 answers
72 views

2D Point subclass of complex builtin

I'm writing a pure-python geometry tool for technical drawings / computational geometry (not a solver, as a solver has to work with constraints). I've already mentioned a previous version on code ...
ToAskOrNotToAsk's user avatar
0 votes
2 answers
139 views

Generate random password from a list of allowed characters

The code itself is a random password generator which is encapsulated. The other question about this code is whether it should be encapsulated on its main function. Or is it enough to exist in its own ...
KhodeNima's user avatar
5 votes
1 answer
62 views

Metaclass Wrapping Builtin to Enforce Subclass Type

This metaclass utility is written to make subclassing builtins easier, such as int, str, and most importantly, ...
ToAskOrNotToAsk's user avatar
0 votes
0 answers
31 views

Synchronisation access to a shared class in Python server with async/await

Last week I wrote a simple server on FastApi to run ML model to classify a text on Chinese (split text on separate words). When I had clarified work of this model with API, it became time to confirm ...
Gleichmut's user avatar
  • 121
2 votes
1 answer
42 views

Interpolate raster value using Python

I'm new in coding. I have a shapefile (points) and some raster files. My purpose is get the values from all raster to point (each point will get value from 2 or 3 nearest cell,the value on the value ...
Long nguyen duc's user avatar
4 votes
2 answers
382 views

Miller-Rabin Primality Test in Python

I have the following implementation of the Miller-Rabin test in Python: ...
pointySphere's user avatar
10 votes
3 answers
1k views

Here is a Tic Tac Toe game in Python using functions

I am a new programmer, learning from youtube and other sites I can get my hands on. The assignment was clear. Create a Tic Tac Toe game using functions as much as possible and where needed. I am ...
LindaJuniordev's user avatar
5 votes
2 answers
709 views

Fast unpack of SAM flag bitfield to named symbols

...
Crispy13's user avatar
  • 153
0 votes
1 answer
55 views

Receive byte string (high speed position output) from FANUC robot, parse and append to dated .xml file

This script just opens a TCP server to listen for real-time position data from a FANUC robot to pass to another sensor software we are using (Luna Terahertz sensor). So far everything is working great,...
greer92's user avatar
  • 11
9 votes
3 answers
2k views

Optimizing the Egg Drop Problem implemented with Python

I've implemented the Egg Drop Problem using Python. As described in the code, I'm trying to find the highest floor of a 102-story building from which I could drop an egg without it breaking. The ...
Muhammed Abiola's user avatar
2 votes
2 answers
770 views

How can I get my CPU Utilization Down? PYGAME PROJECT

I get 25% CPU usage on this simple project. I hope it's okay if I just post the whole thing. It probably something to do with the rendering code. It's definitely the project though, my fans get loud, ...
DizzyDazzo12's user avatar

1
2 3 4 5
306