# Reading numbers from a file using map

I want to read a list of IDs (as integers) from a file in Python3. The file has a single ID per line and no blank lines.

with open(file_eval_id) as f:
eval_ids = [list(map(int, line.split()))[0] for line in f]


Is there a cleaner way of doing it? I have doubts about referencing the list(...)[0] as the best way.

with open(file_eval_id) as f:

• You probably don't even need to .strip(). – 200_success Oct 8 '17 at 14:42
• Since there is only one ID per line, there is no need to use the .strip() – user3079474 Oct 8 '17 at 17:05
• Yes, true. int will discard the end of line. – Roman Susi Oct 8 '17 at 17:36