Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94370 additions and 23234 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import string
|
||||
if hasattr(string, ''ascii_lowercase''):
|
||||
if hasattr(string, 'ascii_lowercase'):
|
||||
letters = string.ascii_lowercase # Python 2.2 and later
|
||||
else:
|
||||
letters = string.lowercase # Earlier versions
|
||||
|
|
@ -7,14 +7,14 @@ offset = ord('a')
|
|||
|
||||
def countletters(file_handle):
|
||||
"""Traverse a file and compute the number of occurences of each letter
|
||||
"""return results as a simple 26 element list of integers.
|
||||
return results as a simple 26 element list of integers."""
|
||||
results = [0] * len(letters)
|
||||
for line in file_handle:
|
||||
for char in line:
|
||||
char = char.lower()
|
||||
if char in letters:
|
||||
results[offset - ord(char)] += 1
|
||||
# Ordinal of 'a' minus ordinal of any lowercase ASCII letter -> 0..25
|
||||
results[ord(char) - offset] += 1
|
||||
# Ordinal minus ordinal of 'a' of any lowercase ASCII letter -> 0..25
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue