December 2018
Beginner to intermediate
682 pages
18h 1m
English
We can initialize an empty list, read the file line by line, split each line, and append the second element to our list:
evens = []with open as f: for line in f.readlines(): evens.append(line.split()[1])
Of course, you can also do this in a one-liner:
evens = [int(x.split()[1]) for x in open('evens.txt').readlines()]
We are just trying to go step by step, following the Zen of Python: simple is better than complex.