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
6 votes
2 answers
102 views

Schedule a series of 1:1 contests so that each entrant plays against every other

My sister is organizing a Majong tournament. She wants to set up a set of round-robin rounds. There will be 16 players at 4 tables; 4 players per table. Players will play 5 rounds. She wants every ...
JDT's user avatar
  • 81
1 vote
1 answer
111 views

Advent of Code 2023 - Day 2: Cube Conundrum

Part 1: The challenge involves analyzing recorded games where an Elf reveals subsets of cubes in a bag, each identified by a game ID. The goal is to determine which games would be possible if the bag ...
Harith's user avatar
  • 4,031
2 votes
2 answers
317 views

Advent of Code 2023 Day 3, Part 2 in Python

Part 2 I'm not sure if my solution covers all edge cases. The puzzle goes as follows: Given some input like this: ...
havocds's user avatar
  • 83
3 votes
1 answer
87 views

Encrypted websocket chat using AES (EAX) and RSA for signing

For learning purposes and because it really interests me I am trying to get a better understanding of cryptography by trying to make my own basic secure chat-application. I posted a first version of ...
O'Niel's user avatar
  • 185
1 vote
0 answers
105 views

How to reduce the build time/cache Docker image layer in subsequent GitHub Actions runs?

I have a Dockerfile with ubuntu:22.04 as a base image and a manual Python installation(specific version i.e., 3.11.1) layer which takes a long time. How to cache ...
shaik moeed's user avatar
1 vote
1 answer
97 views

Implementing Preconditioned conjugate gradient

I have implemented the Preconditioned Conjugate Gradient (PCG) method for solving a system of linear equations in Python and I would appreciate it if someone could verify its correctness since I am ...
blov's user avatar
  • 29
3 votes
1 answer
124 views

Encryption implementation for websocket chat (RSA + AES)

For learning purposes I am trying to make a encrypted chat in Python using Websockets. I am using AES and RSA to make it safe. The idea of the chat is that it's a group-chat. Users can join a chat by ...
O'Niel's user avatar
  • 185
5 votes
2 answers
2k views

How to reduce the build time of Docker image layer in GitHub Actions?

I have a Dockerfile with ubuntu:22.04 as a base image and a manual Python installation(specific version i.e., 3.11.1) layer which takes a long time. Approach 1: ...
shaik moeed's user avatar
2 votes
1 answer
63 views

Python optimization search pythagorean triplets

I have an optimization problem. Be it about code, algorithm or maths, that, i don't know. My goal is to find pythagorean triplets satisfying a = b + 1 or a = b - 1. m and n are the triplets generators....
MarvinLeRouge's user avatar
1 vote
1 answer
64 views

Python Runtime Config

I am implementing runtime configuration for a python package. I am doing this in mypkg.config.__init__.py. The idea is to load the configuration from a JSON file ...
farhanhubble's user avatar
3 votes
2 answers
438 views

Hardware API, primarily for Error handling

I have a piece of equipment that I am interacting with. The manufacturer provided an SDK and some simple examples of how to interact with the device. However, I need to write an API for interacting ...
Michael's user avatar
  • 193
1 vote
1 answer
86 views

Extra 0's after rounding [closed]

In a project i am doing for AP CSP, I am attempting to make a calculator that can do sig figs, and there is always a ton of extra 0's after i round the number as seen in the picture i attached the ...
typicaljujunon's user avatar
3 votes
1 answer
137 views

Fuel Gauge Python

I was wondering if my code is good or maybe if it could be written better or simpler. The task was to implement a program that prompts the user for a fraction, formatted as X/Y, wherein each of X and ...
Hoodati's user avatar
  • 33
-1 votes
0 answers
53 views

Function to find successive primes with sums of previous terms as divisiors

Is this a successful piece of code and an appropriate way to rephrase the mathematical notation? Currently it does not find pairs, so I wonder how to approach reasoning deductively about this problem ...
Attila Vajda's user avatar
2 votes
1 answer
216 views

Python integer optimization with PuLP involving polynomials that I think can be faster

I have a problem where we are given multivariate polynomials in variables like y_i and z_j and the goal is to express them as sums of products of terms of the form y_i-z_j with nonnegative integer ...
Matt Samuel's user avatar
1 vote
1 answer
45 views

Make a script to call pager duty's API and update on call

I made this script it works, I'm just looking for ways to make it better/reading to get better. ...
Alex Orbit's user avatar
2 votes
1 answer
113 views

Advent of Code Day 2 in Python

problem for day 2 Part 1 You're launched high into the atmosphere! The apex of your trajectory just barely reaches the surface of a large island floating in the sky. You gently land in a fluffy pile ...
code writer 3000's user avatar
0 votes
1 answer
57 views

DB Layer of a project management CLI

I am (re)writing a project management CLI and want to put it on a solid foundation concerning the database connections and testing. My focus was to build a DB class which is easy to test and could be ...
Koala's user avatar
  • 103
3 votes
1 answer
61 views

Simulating a Moving Average Process

I was studying stochastic processes and thought to independently simulate a moving average process. ...
insipidintegrator's user avatar
1 vote
1 answer
79 views

Managing users via SQLAlchemy DB model (updated)

I am currently in the process of writing a system application that will be operated by multiple users. This will require individual users to access the application while limiting access to those that ...
Michael's user avatar
  • 193
0 votes
0 answers
64 views

Is this iterative inorder traversal algorithm well-known?

I was concerned about the approach in Morris traversal algorithm and came up with simpler solution that uses parent pointers in nodes. The constraints were following: Time Complexity: O(n) Space ...
Max's user avatar
  • 1
2 votes
1 answer
184 views

Finding the longest path on a grid with obstacles from the top to the bottom

I have a rectangle of . (platforms) and # (obstacles). I can start at any platform in the top row and go to the left, right or ...
Aliaksei Badnarchuk's user avatar
6 votes
1 answer
82 views

Optimizing __getitem__ for a bioinformatics script in Python

I'm writing a script for a bioinformatics application in Python that iterates through several sequences looking for amino acids in specific positions to calculate their frequency in relation to a ...
Eduardo Menotti's user avatar
2 votes
0 answers
85 views

NLP pre-processing function optimization as it is extremely low on 92Mb data set

I have a data set that is of 300,000 rows approximately and two columns, each row contains a string, some might be larger than others. All in all, the data set in a ...
Louis's user avatar
  • 121
10 votes
4 answers
2k views

Number to text in Python

I'm kind of new to programming and I would need a suggestion whether there is a better way to solve this exercise. I need to write a function dict_of_numbers() that ...
fraber's user avatar
  • 151
0 votes
0 answers
44 views

Waiting time display app in Python

This application is for restaurant patrons to know how long they have to wait in line. We would like to design a more sophisticated GUI interface, but do not know how to go about it. Please let me ...
Mako's user avatar
  • 1
3 votes
1 answer
119 views

Simple Tic-tac-toe in Python

I am a beginner programmer who coded a simple Tic-tac-toe in Python for practice. Any feedback, especially regarding best practices and tidying up the code, is appreciated. ...
smwt's user avatar
  • 185
1 vote
1 answer
261 views

Is it a correct way to read a file contents using paramiko (SSH, SFTP client)?

Is my implementation of _read_contents (3 lines) fine, or does it create a potential problem (e.g. passing part of an object that has to be destroyed, or a ...
Yulia V's user avatar
  • 633
2 votes
2 answers
76 views

Dictionary additional function implementations

I've written a utility class BetterDict to help me on some of my other projects. I've implemented the &, ...
Linny's user avatar
  • 10k
3 votes
1 answer
128 views

Pentomino solver in Python

When I was a child, I used to play Ubongo board game, recently I discovered Pentomino puzzle and I wanted to create a custom solver in python for it. Here is what I got: ...
Riomare's user avatar
  • 31
1 vote
1 answer
78 views

HackerRank Algorithm Problem: Climbing the Leaderboard (Python)

Here is the Hackerrank problem which is related to dense ranking and below is my solution which didn't pass the time limit cases. Any better way to optimize this? ...
peternish's user avatar
0 votes
0 answers
32 views

cubic spline routine

I tried to implement the cubic spline algorithm in cython. I want to ask how I can make the code more efficient in terms of speed. Any suggestions or references ...
John's user avatar
  • 1
0 votes
1 answer
63 views

Python GUI Based IP location digger

Greetings. I'm a newbie python developer who just started using PyQt5 as his major GUI development tool. Because of this, I have started a side project known as NyvoAI, just for gaining more knowledge ...
KhodeNima's user avatar
  • 349
1 vote
0 answers
38 views

Making my code shine and pro: Python in Azure Function Retrieveing the Data From Rest API

The code retrieves the data from PBI API - it's my first one and I would like to learn how to make it pro. Here is the list of my questions: Can you please analyze 2 functions: GetReports and ...
user1956634's user avatar
3 votes
1 answer
134 views

Settings and global variables in one place

I have a configuration (YAML) file used across related modules. I also have a few additional variables to be accessed globally in my modules. I want to have them at one place (an instance of a class ...
Imtiaz's user avatar
  • 35
2 votes
2 answers
103 views

Dynamic python config reader

I am looking for a code review on the following code. Say I have a simple example class, something like the following: ...
Silverwilly's user avatar
3 votes
1 answer
243 views

Cleaning Yaml Data in Python

I'm working with a bunch of yaml files that are rather sloppy. This is outside of my control unfortunately, so I'm trying to clean up the data after the fact. My approach doesn't allow for nested ...
Jan van Wijk's user avatar
3 votes
2 answers
286 views

Trailing Digits

https://www.acmicpc.net/problem/23204 I've solved a programming challenge where you need to count the occurrences of a specific digit at the end of the product of multiples of a given number within a ...
qleoz12's user avatar
  • 141
1 vote
1 answer
93 views

Theme Toggle switch refactoring

I built a theme toggle switch function, and refactored it following an awesome suggestion in a previous answer. Before the refactoring the function looked like this: ...
Attila Vajda's user avatar
1 vote
2 answers
262 views

Split netmask or ip address

I've written a python function to split a netmask or an ip address. The code is about to become part of a custom router api. ...
Looser User's user avatar
3 votes
1 answer
63 views

Clock markings refactoring for enhancement opportunities

The given Python code snippet is for drawing clock markings. ...
Attila Vajda's user avatar
1 vote
5 answers
3k views

Finding a distinct triplet where the sum of the values is divisible by a given number

Given an array a and a number d, I want to count the number of distinct triplets (i,j,k) such that i<j<k and the sum aᵢ + aⱼ + aₖ is divisible by d. Example: when a is ...
Athul Raju's user avatar
0 votes
1 answer
59 views

Refactoring random time values list generator function

This function outputs random values in a list. Although I was happy to craft this solution from a more complex version, and it looks really cool to me, I wonder if it is an example of clean code. How ...
Attila Vajda's user avatar
0 votes
1 answer
33 views

Simplifying and enhancing readability in time angle calculation

Is the following Python code, which calculates hand angles based on current time, simple and readable? What alternative approaches can enhance simplicity and readability? Are there concise one-liner ...
Attila Vajda's user avatar
1 vote
0 answers
57 views

Telegram bot computing a heavy I/O task

Introduction I have a telegram bot based on aiogram framework. It does GPU intensive computations locally then user makes a request and outputs a text file after ...
Amir Suleymanov's user avatar
1 vote
1 answer
75 views

Password database: saving and loading encrypted files

I'm writing a password manager application, mostly with the goal of learning about proper handling of encryption. Here is my code responsible for encrypting/decrypting passwords and loading to/from ...
gazoh's user avatar
  • 3,149
-1 votes
1 answer
112 views

HackerRank Project Euler 12 (Python) | Highly Divisible Triangular Numbers

I again share my Python code which didn't pass time limit test cases in the HackerRank contest of ProjectEuler. ...
peternish's user avatar
1 vote
1 answer
76 views

Project Euler 10(Python) | Summation of Primes

This is my Python3 code which solved the 10th problem of Project Euler. I haven't passed the last 2 time limit test cases. ...
peternish's user avatar
0 votes
0 answers
43 views

GUI Tic Tac Toe with unbeatable AI - styling

This question contains code of the updated version of my GUI Tic Tac Toe game, the code is about the styling and playing piece customization. It is related to: GUI Tic Tac Toe game with UNBEATABLE AI ...
Ξένη Γήινος's user avatar
2 votes
1 answer
182 views

GUI Tic Tac Toe game with UNBEATABLE AI players

This is an updated version of my Tic Tac Toe game with AI players, it is related to GUI Tic-Tac-Toe game with six AI players - part 1: the UI. But that question is more than two weeks old and no one ...
Ξένη Γήινος's user avatar