Read a file into a list of lines in Python

Method 1: Use readlines()

with open(filename) as f:
    lines = f.readlines()

Method 2: Use the list constructor

with open(filename) as f:
    lines = list(f)