Created
June 11, 2011 15:32
-
-
Save llimllib/1020668 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. You can access strings just like they were arrays, with []: | |
s = "testing" | |
assert s[0] == "t" | |
#which means that you don't need to split each number like you do in lines 36 and 37 | |
# 2. If you ever find yourself writing out numbers in sequence, you're probably doing something | |
# better accomplished with a for loop. Thus, this: | |
for number in datalist: | |
if number[0] == '1': | |
number_count[1] += 1 | |
total_count += 1 | |
elif number[0] == '2': | |
number_count[2] += 1 | |
total_count += 1 | |
#... | |
elif number[0] == '9': | |
number_count[9] += 1 | |
total_count += 1 | |
else: | |
non_number += 1 | |
# Is better written as: | |
for number in datalist: | |
for n in '123456789': | |
if number[0] == n: | |
number_count[int(n)] += 1 | |
total_count += 1 | |
non_number = len(datalist) - total_count |
Glad it was useful, let your hammer rain down blows upon those who would select numbers from an unnatural distribution!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, love lines 24-28, amazing way to do it! I was missing 'int(n)' and the inception for loops using '123456789'.
Brilliant, thanks! Pushing changes now. Document falsifiers will be quaking in the shadows of BENFORDS HAMMER.