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,243
questions
29
votes
4
answers
7k
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 ...
59
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 ...
26
votes
1
answer
50k
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.
...
15
votes
4
answers
346
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
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, ...
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 (+, -...
13
votes
3
answers
2k
views
AniPop - The anime downloader
Note: The topics of performance and Selenium/BS4 have not yet been addressed,
so this question can still receive a better answer!
Chat Room: https://chat.stackexchange.com/rooms/100275/anipop-...
11
votes
3
answers
12k
views
Bubble sort algorithm in Python
I'm starting to implement basic sorting algorithms. Criticisms on the implementation is welcome.
...
10
votes
1
answer
14k
views
K-Mean with Numpy
I have implemented the K-Mean clustering Algorithm in Numpy:
...
8
votes
3
answers
92k
views
Python Tic Tac Toe Game
I made this as a personal challenge. It seems to work fine as I can't find any bugs and am happy with how it runs, but I am interested in what I should do to make the code more professional.
I think ...
8
votes
2
answers
1k
views
Selection Sort Algorithm (Python)
Selection Sort
The selection sort algorithm sorts a list by finding the minimum
element from the right unsorted part of the list and putting it at the
left sorted part of the list. The ...