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
0answers
72 views

Codewars Kata - Tickets Queue

The challenge: You managed to send your friend to queue for tickets in your stead, but there is a catch: he will get there only if you tell him how much that is going to take. And everybody can ...
-2
votes
1answer
85 views
2
votes
0answers
55 views

GRU-Autoencoder training

I'm training a GRU auto-encoder and my current code is very slow.I believe it's predict_captions function that takes most the time. Any suggestion to optimize this code? ...
8
votes
2answers
4k views

Age verification module in Python

I wrote an age verification module in Python 2.5 . How can I improve on current_year? import time perhaps? ...
4
votes
1answer
48 views

Convert string to fishy and fishy to string

Inspired by this question. Here's the code: ...
12
votes
5answers
2k views

A Simple Battleship Game

I have just finished learning basic-intermediate Python subjects and wanted to test myself. This Battleship game is the third game i have written. ...
7
votes
1answer
76 views

Lower, Higher, or Same Card Game

This is my second script in my first language so I'm trying to get oriented and better foundations. I noticed in the while loop I got really messy but I couldn't ...
4
votes
1answer
109 views

Money change/minimum coin algorithm

How can I speed up this code? ...
4
votes
1answer
54 views

Paginating API with “next” Pythonically

I'm wondering if there's a more Pythonic way to keep paginating an API endpoint until there's no next key in the response. The thing that bothers me the most is the ...
9
votes
3answers
333 views

The parking machine implementation

I am interesting in the topic of finite automata, so I started over by implementing a parking machine from this video: Computers Without Memory - Computerphile to understand conceptions. Didn't do ...
2
votes
1answer
47 views

Django Unified Method for Deleting Instances of Any Model

This code works, but I don't know if there are better and especially safer ways to do this. For context: this is a Django view (Python) and I wanted to unify the deletion methods because there were ...
5
votes
2answers
89 views

Find minimal number of days to meet all your friends

I was asked this in an interview yesterday: You get an array of segments (segment contains 2 numbers, representing days count (say in a month, but could be in a year, etc.): start, end). You need to ...
3
votes
0answers
44 views

crossword using tkinter without classes and objects

For my python project, I wanted to make a crossword game GUI with sql connectivity to display high scores so I tried to learn tkinter the only difficulty was that I cannot use classes or objects as ...
6
votes
1answer
84 views

Looking for general feedback on Python OOP banking project

I am in the process of trying to teach myself Python, and am at a point where I feel some general feedback on my styling/code efficiency would be super useful in order for me to progress. I have ...
1
vote
2answers
141 views

HackerRank Problem - “Queen's attack II”

I am new to python and coding in general and I recently found HackerRank. I have been mostly doing easy problems until now. Today, I saw the problem "Queen's Attack II" (https://www.hackerrank.com/...
5
votes
2answers
77 views

General matrix class

I have written a matrix class using python, allowing me to perform a variety of operations on matrices. I'm pretty happy with how it performs, and everything works fine. However, I feel like the way I'...
-1
votes
2answers
110 views

TrainSet Practice Problem from CodeChef

A dataset consisting of N items. Each item is a pair of a word and a boolean denoting whether the given word is a spam word or not. There shouldn't be a word included in the training set that's ...
2
votes
1answer
51 views

Manual Regression Tree using Python

I wrote a code to create a regression tree for a synthetic train data of size Np. The idea is, first I have the source node (which consists of all set of points) ...
6
votes
1answer
102 views

Count swaps needed to order a list of integers

I wrote this code since I'm going through the hackerrank challenges, however, it takes way too long to run. Its function is described on the title, but just to clear it up, we need to count the ...
0
votes
1answer
39 views

Assigning a numerical value to each alphabet in corresponding order and then summing any inputted word

I made a function that outputs the sum of the value of each letter in a word. For example if I input hello my function would output 52. ...
5
votes
1answer
66 views

Python logging - wrapper

I am new to writing utility functions. I wrote a python program to return a Python logger with custom settings. Please review this code and provide comments on how to improve it. I am looking for ...
4
votes
3answers
59 views

Consolidating a dictionary from nested dictionary

Currently learning from "LPTHW - Zed Shaw" and "Automating the boring stuff". There is a nested dictionary of the type ...
13
votes
1answer
16k views

Decorator to measure execution time of a function

This decorator adds the elapsed time to a function's attributes when applied. My concerns: Is the code pythonic? Could this code be useful? Should I just use the ...
6
votes
2answers
7k views

Two-player dice game for NEA task computer science (Updated)

This is a game for two users who roll 2 dice 5 times. If the total of dice is even the player gains 10 points; if it is odd, they lose 5. If there is a draw after five rounds then both users will ...
2
votes
1answer
69 views

Interactive Tower of Hanoi

I created this program some time ago. It shows you how to solve tower of hanoi for n disks, step by step. Here's the code: ...
7
votes
1answer
601 views

Python 2.7 Tower of Hanoi game with ASCII graphics

The game generates a fixed, "animated" game board via ASCII characters that is reprinted and cleared after each valid move. The format of the input for making moves is described in the script. You ...
11
votes
1answer
117 views

Slow image generation

I build a Tower of Hanoi solver which print the solution as an image It works as expected but generating the image is relatively slow compared to the time to calculate the answer. Here is the code: ...
7
votes
1answer
3k views

Solving the Reve's puzzle

I'm trying to solve the Reve's puzzle (a variant of the Tower of Hanoi puzzle with four pegs). This is what I've come up with so far: ...
12
votes
2answers
2k views

Tower of Hanoi Recursive Implementation using Python with OOP

I have just finished a small program for Tower of Hanoi using recursion. I did it to practice OOP which I recently learnt. It took me about 2 hours to research about the recursive algorithm and write ...
2
votes
1answer
1k views

Tower of Hanoi: graphical representation of optimal solution

I wrote a program to show graphically the solution of the problem of the Tower of Hanoi. Here is a video of an example run. The logic of the solving is taken from StackOverflow (see links in ...
11
votes
0answers
211 views

Population dynamic simulation on biological information maintenance 2

This question is the follow-up to this previous question. Background Using this simulation I investigate a system in which enzymes proliferate in cells. During the replications of enzymes, ...
4
votes
1answer
12k views

Find position of a word in a list in Python

The aim of this program is to say which position a word is in a list. This is just a basic version of it. I made to see if I could shorten it more than what it is currently. ...
3
votes
3answers
71 views

Recursive Error Handling in Python with a limited amount of tries

I have a class method that is set up to make requests to an API and I'm having issues handling the possible errors that could arise by trying to communicate with that server. The idea is if an error ...
1
vote
0answers
43 views

Optimized AWS Lamda purpose [closed]

I'm looking for optimized code with faster execution time. This writes CSV to parquet with the max size of 64 MB chunks. we are trying to concatenate the csv file contents being written as an parquet ...
2
votes
2answers
138 views

HashMap in Python

This is a HashMap implementation written in Python. All the methods are based on the java implementation of a HashMap. Any and ...
6
votes
1answer
77 views

Portfolio optimization using genetic algorithm

I'm working on a (naïve) algorithm for portfolio optimization using GA. It takes a list of stocks, calculates its expected returns and the covariance between all of them and then it returns the ...
8
votes
1answer
98 views

Finding unimplemented tasks on Rosetta Code using Requests

This is a Find unimplemented tasks task from Rosetta Code: Given the name of a language on Rosetta Code, find all tasks which are not implemented in that language. There is already a solution ...
8
votes
3answers
625 views

Creating an affinity-matrix between protein and RNA sequences

I wrote an algorithm that analyzes protein-RNA interactions and I found that the following function is the bottleneck that causes performance issues: ...
10
votes
2answers
133 views

System design - Jaipur board game learning agent

Link to my previous question. I've implemented the other features of the board game, and made a simple learning method that stores state values and makes optimal moves based on that. I've used some ...
3
votes
2answers
82 views

Merge sort implementation in python 3

I have implemented a Merge sort in Python 3, and it works well. If anything needs to be improved, I would appreciate the criticism. ...
2
votes
0answers
41 views

Python Async Reqeust using Tor and User-Agent Rotation

The code below will scrape data from three APIs. The APIs are for property listings. So, for each listing, I will have one request. There will be around 20000 requests. That's why I use ayncio to make ...
-1
votes
1answer
54 views

Find minimum and maximum in a string with spaces

I've made a function that outputs the highest and lowest values from a string containing a space-separated list of numbers. For example, if given ...
2
votes
2answers
2k views

Improving SQLITE3 Left Join Performance

I occasional write simple yet long Python scripts using Sqlite3 (I'm not proficient with functional or object oriented programming... yet) Usually my Sqlite3 is blazing fast. I'm used to looping ...
2
votes
1answer
62 views

Collatz sequence using Python 3.x

I created this program originally for Project Euler 14. Here's the code: ...
5
votes
2answers
101 views

Scrabble Scorer in Python

I made this Scrabble with care since it will be mainly used by family that will not understand the error codes so that is why I catch basically every possible error, to make it user friendly. I have ...
5
votes
3answers
147 views

Divide by two a number in base -2

I was given this coding challenge when a applying for a summer internship but didn't get selected for the next round and I was curious if it could be improved. The problem says: Given a number in ...
5
votes
1answer
74 views

Normalizing mixed format nested dictionary with delimiter separated keys

I recently worked with some pickle files which had a really strange format where the keys are sometimes delimiter separated with colons and placed in the same depth but also mixed with ordinary key ...
12
votes
4answers
3k views

Password generator in python

Here's a password generator I created. ...
2
votes
3answers
138 views

Smallest letter in a string

As part of my college class, I have to write a program that returns the "smallest" letter in the string. Input is assumed to be a non empty string. "Smallest" is defined as: The smallest decimal ...
6
votes
3answers
531 views

Minimum path sum in a triangle (Project Euler 18 and 67) with Python

Project Euler 18 Project Euler 67 As problem 67 is harder, I'll go with that one: By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum ...