Created
November 18, 2014 05:07
-
-
Save chrismo/47030cd4c07a4cc7f6d4 to your computer and use it in GitHub Desktop.
This file contains 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
Coloured fox fur production, HOPEDALE, Labrador, 1834-1842 | |
#Source: C. Elton (1942) "Voles, Mice and Lemmings", Oxford Univ. Press | |
#Table 17, p.265--266 | |
29 | |
22 | |
2 | |
16 | |
12 | |
35 | |
8 | |
83 | |
166 |
This file contains 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
import time_series | |
def smallest_value(reader): | |
""" (file open for reading) -> NoneType | |
Read and process reader and return the smallest value after the | |
time_series header. | |
""" | |
line = time_series.skip_header(reader).strip() | |
# Now line contains the first data value; this is also the smallest value # found so far, because it is the only one we have seen. | |
smallest = int(line) | |
for line in reader: | |
value = int(line.strip()) | |
# If we find a smaller value, remember it. | |
if value < smallest: smallest = value | |
return smallest | |
if __name__ == '__main__': | |
with open('hopedale.txt', 'r') as input_file: | |
print(smallest_value(input_file)) |
This file contains 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
def skip_header(reader): | |
""" (file open for reading) -> str | |
Skip the header in reader and return the first real piece of data. | |
""" | |
# Read the description line | |
line = reader.readline() | |
# Find the first non-comment line | |
line = reader.readline() | |
while line.startswith('#'): | |
line = reader.readline() | |
# Now line contains the first real piece of data | |
return line | |
def process_file(reader): | |
""" (file open for reading) -> NoneType | |
Read and print the data from reader, which must start with a single description line, then a sequence of lines beginning with '#', then a sequence of data. | |
""" | |
# Find and print the first piece of data | |
line = skip_header(reader).strip() | |
print(line) | |
# Read the rest of the data | |
for line in reader: | |
line = line.strip() | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment