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.
15,537
questions
222
votes
4
answers
24k
views
Calculate SHA1 hash from binary and verify with a provided hash
I applied for a job and they asked me to write code with the following requirements:
Get a "toolbar offer" description from
http..update.utorrent.com/installoffer.php?offer=conduit. Parse the
...
127
votes
6
answers
17k
views
How clean is my snow?
I just wrote a snow animation in Python. I think this is fairly clean but I have a few things that I don't like.
...
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:
...
74
votes
3
answers
20k
views
Monopoly simulator
I was advised by a Reddit user to get my code reviewed on this site.
The complete code is on GitHub.
...
73
votes
5
answers
11k
views
Send a tweet to ISP when internet speed drops
I have written an app in Python 3 which monitors internet speed and will send a tweet to an ISP when the speed drops too low. The app has a config file where the ISP and target speeds can be ...
71
votes
2
answers
97k
views
Redirecting subprocesses' output (stdout and stderr) to the logging module
I'm working on a Python script and I was searching for a method to redirect stdout and stderr of a subprocess to the logging ...
69
votes
4
answers
57k
views
Flappy Bird game clone for a beginners' programming class
I'll soon begin teaching a beginners' programming class. It's voluntary, so I thought I'd make it interesting by teaching Python programming and then introduce the kids to Pygame, so that they can ...
62
votes
6
answers
5k
views
Accurate email syntax validation (no seriously)
So a friend happened to show me how odd and specific the general email syntax rules are. For instance, emails can have "comments". Basically you can put characters in parentheses that are just ignored....
61
votes
10
answers
4k
views
Using separate functions for Project Euler 1
I started programming with Java and C++, so I'm used to having a 'main' function that calls other functions that do the actual work. At university I was always told that doing actual computation in ...
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 ...
58
votes
3
answers
69k
views
Dynamic programming knapsack solution
I wrote a solution to the Knapsack problem in Python, using a bottom-up dynamic programming algorithm. It correctly computes the optimal value, given a list of items with values and weights, and a ...
57
votes
2
answers
3k
views
Counting all the vowels in a passage of text
My son just started high school and in Math, he was asked to do some stats homework. The exercise was to count all the vowels in a passage of text, then answer some questions about frequency.
Out of ...
52
votes
3
answers
170k
views
Finding the closest point to a list of points
I'm trying to find the closest point (Euclidean distance) from a user-inputted point to a list of 50,000 points that I have. Note that the list of points changes all the time. and the closest distance ...
48
votes
1
answer
4k
views
The right way to hang a man
Problem:
I have seen a few questions around hangman. Usually this is done in a very hackish way, which usually can not be generalized any further. My thought or question is about the creation of the ...
47
votes
8
answers
10k
views
Prettify math formula in code
I have a function to calculate the normal distribution in Python:
...