Skip to content

Instantly share code, notes, and snippets.

@vzts
Created June 5, 2019 14:23
Show Gist options
  • Save vzts/26908404489eaafd1af949128a3e7790 to your computer and use it in GitHub Desktop.
Save vzts/26908404489eaafd1af949128a3e7790 to your computer and use it in GitHub Desktop.
map.py
def read_map(file_name: str):
# read file
f = open(file_name, 'r')
content = f.read()
# save in two dim array
map = []
# separate by lines
lines = content.split('\n')
# feed line by line with index
for x, s in enumerate(lines):
# ex) arr = [[0, 1, 2], [0, 1, 2], [0, 1, 2]], arr[0][2]
map.append([])
# feed char by char
for c in list(s):
map[x].append(int(c))
# loop through array and print
for l in map:
for c in l:
if c == 0:
print(' ', end='')
elif c == 1:
print('☐', end='')
elif c == 2:
print('✹', end='')
elif c == 3:
print('❤︎', end='')
else:
raise Exception('invalid value!')
print('')
if __name__ == '__main__':
read_map('map_data.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment