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
5 votes
2 answers
389 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/...
3 votes
1 answer
68 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. ...
0 votes
0 answers
29 views

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

Here is a sample JSON output myJSON: ...
1 vote
0 answers
23 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. (The actual tic-tac-toe logic is being done by a ...
3 votes
3 answers
864 views

Given a list of digits, construct the largest number divisible by 3

What is the performance of this program? What should I do differently to optimize performance (O(n))? How would you grade it relative to what defines an optimal, elegantly-written program? Input: A ...
0 votes
1 answer
119 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 ...
3 votes
3 answers
167 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 ...
15 votes
4 answers
6k views

Goldbach's conjecture algorithm

I did a Goldbach's Conjecture exercise and got it to work. It's pretty slow though and I was wondering how I could optimize it. ...
0 votes
0 answers
39 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 ...
3 votes
1 answer
97 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 ...
1 vote
0 answers
32 views

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

...
1 vote
1 answer
97 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: ...
-4 votes
0 answers
31 views

Eclipse for Data Science: Loading and Analyzing a Dataset with Python [closed]

I'm using Eclipse for my data science projects, and I'm struggling with loading and analyzing a dataset using Python within Eclipse. Specifically, I want to load a CSV dataset, perform some basic data ...
3 votes
1 answer
121 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 ...
1 vote
1 answer
65 views

Getting one company from two tables

Currently I'm working with fastapi, sqlalchemy to connect to multiple databases. It checks params to ensure it has company_name, ...
1 vote
0 answers
34 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 ...
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 ...
1 vote
0 answers
46 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 ...
2 votes
2 answers
295 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 ...
2 votes
1 answer
440 views

PHP / Laravel - Using Python to image manipulation

I have a simple job class in Laravel, that will do the following: Get all the images in a folder /original Perform some image manipulation on each image Save each ...
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 ...
3 votes
1 answer
68 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 ...
5 votes
1 answer
73 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. <...
2 votes
1 answer
60 views

It acts as a booking system allowing user to create an account, create bookings and cancel bookings

As the title says, it manages to create accounts, create bookings and cancel them. I am relatively new to coding, so i was wondering how did i do? What are some improvements that i could do? Any ...
7 votes
4 answers
27k views

Algorithm to get an arbitrary perpendicular vector

Is there a more efficient/direct way to find an arbitrary perpendicular vector of another vector? ...
1 vote
1 answer
49 views

Start Screen for pygame

I'm making a Start Screen class for my game, it has 3 buttons and they're spread out horizontally on the screen. The screen also has a scrolling background, moves from top to bottom. It's a very basic ...
2 votes
1 answer
93 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. ...
1 vote
1 answer
80 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 ...
3 votes
1 answer
346 views

Text RPG in Python

I'm a beginner in python and my code looks a little cluttered and a lot of lines are being duplicated, so I was wondering if I could get some suggestions on how to declutter and improve? ...
3 votes
1 answer
45 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 ...
0 votes
0 answers
64 views

Gacha Nox Webgame Bot

0 So there is this gachanox. You can play Gacha Nox in full screen. I wrote a python script which "plays" the game on the website by clicking the arrow keys. I would like to know what can be ...
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 ...
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 ...
5 votes
2 answers
2k views

Username-Password Matching Program

I started university this semester. Can you review my code and share your thoughts with me ...
2 votes
1 answer
62 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 ...
1 vote
1 answer
57 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 ...
6 votes
2 answers
976 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 ...
0 votes
2 answers
138 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 ...
4 votes
1 answer
1k views

Login function with python and SQLite

I'm a new programmer who is currently working on a personal project. It is supposed to be a login program which stores user data in a SQLite database. I was wondering if anyone could look at my code ...
4 votes
1 answer
833 views

Python 3 minesweeper tkinter game

I have just finished my minesweeper game using tkinter and would like to know how I could improve my program. ...
0 votes
2 answers
137 views

Program for monitoring file in Combined Log Format

After encountering a suggestion that monitoring a log file for a webserver could allow for the implementation of automatically analyzing and handling of certain events (that might require altering ...
4 votes
1 answer
94 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 ...
1 vote
1 answer
153 views

Robot battle game Terminal game code

This is a project for a class and all the requirements are met, I just wanted to do a little more and make this even better. All the changes that I've made are already implemented and I would like to ...
4 votes
2 answers
121 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 ...
4 votes
2 answers
129 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, <...
2 votes
2 answers
120 views

OOP tic-tac-toe

I have created my first personal project - tic tac toe game. It is my first time approaching code using Object-Oriented paradigm and I would like to get feedback on it and on aspects where I can ...
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 ...
1 vote
2 answers
2k views

Reverse Message Program

...
5 votes
1 answer
61 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, ...
0 votes
0 answers
29 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 ...

1
2 3 4 5
306