Created
March 28, 2020 04:31
-
-
Save bergpb/3e6b9bf9a6c91d9d64c28d220e0ab40f to your computer and use it in GitHub Desktop.
Read a file line by line and put content into a list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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