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.
1,292 questions
29
votes
4
answers
8k
views
Sieve of Eratosthenes - Python
I've been doing a lot of Project Euler lately and just wanted to make sure my implementation was as good as it could be. Does anyone have any suggestions to speed this up?
...
84
votes
4
answers
22k
views
Function to print command-line usage for a program [closed]
The following function works well to print out a help message for the program I have written. It prints a multi-line string message that describes the command line usage with some examples:
...
18
votes
1
answer
7k
views
Plot timings for a range of inputs
When writing Code Review answers, it becomes often necessary to measure how long the modified code takes vs how long the OP's code takes. I needed a nice way to visualize this as a function of the ...
60
votes
9
answers
14k
views
Project Euler problem 1 in Python - Multiples of 3 and 5
I'd like suggestions for optimizing this brute force solution to problem 1. The algorithm currently checks every integer between 3 and 1000. I'd like to cut as many unnecessary calls to ...
27
votes
1
answer
51k
views
Snake game using PyGame
I wrote a simple Python snake game which is about 250 lines of code. Can someone give me some advice on how I can refactor/make it better?
game.py
...
11
votes
1
answer
4k
views
Z-Algorithm for pattern matching in strings
I was trying to refactor the following Python code (keeping the same time-complexity) which is an implementation of Z-Algorithm for pattern matching in strings.
...
2
votes
1
answer
156
views
Newspaper Bill Calculator CLI with Python (1 of 3, Core)
Code is posted after explanation.
Due to the size of the project, this is being posted in three separate posts. This also ensures each post is more focused.
Post 2 of 3, CLI: Newspaper Bill ...
19
votes
2
answers
1k
views
Typical password generator in Python
Password generators are extremely popular on CodeReview with beginners to both coding in general and Python in particular, for a number of reasons:
They're (seemingly) easy to implement
They offer an ...
15
votes
4
answers
407
views
From Q to compiler in less than 30 seconds
(See the newer version here: CodeReview question markdown downloader)
As an adjunct to From new Q to compiler in 30 seconds, I've created a Python script to automatically download the markdown from ...
14
votes
1
answer
9k
views
Solving 15 puzzle
I'm trying to solve 15 puzzle using A* algorithm, but something really bad goes on in my get_solution() function that ruins performance. I guess there is a too much ...
7
votes
2
answers
4k
views
Project Euler - Problem 54: testing poker hands
This was a very fun and thought provoking problem, and I'm quite proud of the way I was able to pull it off. I broke it down into 2 parts, testing and comparing.
Testing each group of cards for a ...
7
votes
3
answers
3k
views
Efficiency of Project Euler problem 35
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, ...
6
votes
3
answers
694
views
ASCII-based Lightweight Browser with Clippy-Style Helper in Python (Updated)
This question used to contain a mistake in the code, so I had to debug and reformat it. This is the correct version.
Why I made it
A friend and I wanted to make a lightweight browser, since our ...
15
votes
1
answer
4k
views
Merge n sorted iterators
Over the weekend I was curious about efficiently merging multiple sorted iterators together, and for them to be in sorted order.
This is quite like a challenge on HackerRank:
You’re given the ...
15
votes
2
answers
7k
views
Evaluating arithmetic expressions
I have written some simple code for evaluating expressions. However, I am not sure how well I am following conventions (this is my first time trying to).
Specs for problem:
All binary operators (+, -,...