Skip to content

Instantly share code, notes, and snippets.

@Leask
Created February 11, 2018 07:20
Show Gist options
  • Save Leask/8138985b364cf754e7ce2b5ba0604b6e to your computer and use it in GitHub Desktop.
Save Leask/8138985b364cf754e7ce2b5ba0604b6e to your computer and use it in GitHub Desktop.
Demo for reading text as array in Python3.
array = [];
with open('test.txt', 'r') as f:
while True:
line = f.readline().strip()
if not line:
break
line = list(map(int, line.split(' ')))
array.append(line)
print(array)
10 1 9 9
6 3 2 8
20 10 3 23
1 4 1 10
10 8 6 3
10 2 1 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment