Skip to content

Instantly share code, notes, and snippets.

@bergpb
Created March 28, 2020 04:31
Show Gist options
  • Select an option

  • Save bergpb/3e6b9bf9a6c91d9d64c28d220e0ab40f to your computer and use it in GitHub Desktop.

Select an option

Save bergpb/3e6b9bf9a6c91d9d64c28d220e0ab40f to your computer and use it in GitHub Desktop.
Read a file line by line and put content into a list.
#file.txt
#1 2 3
#4 5 6
#7 8 9
with open('file.txt') as file:
content = file.readlines()
numbers = [line.strip().split(' ') for line in content]
print(numbers)
# [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment