The basic Python way

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset