How to debug
Add a simple print
for each intermediate result.
f = open('States.txt','r')
columns = list(zip(*(map(str, row.split()) for row in f)))
print(columns)
t = columns[2]
print(t)
result = tuple(int(x[0:10]) for x in t)
print(result)
print(max(result))
The output looks like:
[('AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS'), ('South', 'West', 'West', 'South', 'West', 'West', 'Northeast', 'South', 'South', 'South', 'West', 'West', 'Midwest', 'Midwest', 'Midwest', 'Midwest'), ('4863000', '742000', '6931000', '2988000', '39250000', '5541000', '3576000', '952000', '20612000', '10310000', '1429000', '1683000', '12802000', '6633000', '3135000', '2907000')]
('4863000', '742000', '6931000', '2988000', '39250000', '5541000', '3576000', '952000', '20612000', '10310000', '1429000', '1683000', '12802000', '6633000', '3135000', '2907000')
(4863000, 742000, 6931000, 2988000, 39250000, 5541000, 3576000, 952000, 20612000, 10310000, 1429000, 1683000, 12802000, 6633000, 3135000, 2907000)
39250000
Find the statement to modify
Since you need the states to filter for IL
, the first statement needs a filter added:
columns = list(zip(*(map(str, row.split()) for row in f)))
So we can decompose it. Then try to add a filter after each row is split.
Decompose the nested statement
Unwrap the parentheses step by step. This is also known as refactoring of type Extract Variable:
mapped = (map(str, row.split()) for row in f) # generator mapping needs to be decomposed
zipped = zip(*mapped) # unpacked as tuples
columns = list(zipped)
Now lets further decompose the complex generator-mapping:
mapped = (map(str, row.split()) for row in f)
# could call it a file-reading spliterator