9951 explained code solutions for 126 technologies


pythonHow to store each line of a file as an index of a list


file_lines = [line.strip() for line in open("filename.txt")]ctrl + c
file_lines

is a list of lines in the given file

line.strip()

remove whitespace from both sides of the string

filename.txt

file to read lines from