Skip to content

Commit

Permalink
made rotate_2d_list and string_to_2d_list return list of lists like t…
Browse files Browse the repository at this point in the history
…he name implies, not list of tuples.
  • Loading branch information
pokepetter committed Dec 6, 2024
1 parent c732919 commit 833e3a5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ursina/array_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ def chunk_list(target_list, chunk_size):


def rotate_2d_list(target_2d_list):
return list(zip(*target_2d_list[::-1])) # rotate
return [list(row) for row in zip(*target_2d_list[::-1])] # rotate


def string_to_2d_list(string, char_value_map={'.':0, '#':1}):
from textwrap import dedent
grid = dedent(string).strip()
grid = grid.split('\n')
grid = [[char_value_map.get(e, 0) for e in line] for line in grid]
grid = list(zip(*grid[::-1])) # rotate
grid = [list(row) for row in zip(*grid[::-1])] # rotate
return grid

if __name__ == '__main__':
Expand All @@ -174,10 +174,10 @@ def string_to_2d_list(string, char_value_map={'.':0, '#':1}):
.##..#..#.####..#..
'''
expected_result = rotate_2d_list([
(1,0,0,1, 0, 1,1,1,0, 0, 1,1,1,1, 0, 0,1,0,0),
(1,0,0,1, 0, 1,0,0,1, 0, 1,1,1,0, 0, 0,1,0,0),
(1,0,0,1, 0, 1,1,1,0, 0, 0,0,0,1, 0, 0,1,0,0),
(0,1,1,0, 0, 1,0,0,1, 0, 1,1,1,1, 0, 0,1,0,0),
[1,0,0,1, 0, 1,1,1,0, 0, 1,1,1,1, 0, 0,1,0,0],
[1,0,0,1, 0, 1,0,0,1, 0, 1,1,1,0, 0, 0,1,0,0],
[1,0,0,1, 0, 1,1,1,0, 0, 0,0,0,1, 0, 0,1,0,0],
[0,1,1,0, 0, 1,0,0,1, 0, 1,1,1,1, 0, 0,1,0,0],
])

_test(string_to_2d_list, test_input, expected_result)
Expand Down

0 comments on commit 833e3a5

Please sign in to comment.