Currently, I have made this code
def grid_maker(h,w):
grid = [[["-"] for i in range(w)] for i in range(h)]
grid[0][0] = ["o"]
print grid
>>>grid_maker(3,5) => [[['o'], ['-'], ['-'], ['-'], ['-']], [['-'], ['-'], ['-'], ['-'], ['-']], [['-'], ['-'], ['-'], ['-'], ['-']]]
I want to make another function that will take in the produced 2d array and print it out such that it is in this format:
o----
-----
-----
However, I am unsure where to start.
If you want to "pretty" print your grid with each sublist on its own line, you can use pprint:
>>> grid=[[['o'], ['-'], ['-'], ['-'], ['-']], [['-'], ['-'], ['-'], ['-'], ['-']], [['-'], ['-'], ['-'], ['-'], ['-']]]
>>> from pprint import pprint
>>> pprint(grid)
[[['o'], ['-'], ['-'], ['-'], ['-']],
[['-'], ['-'], ['-'], ['-'], ['-']],
[['-'], ['-'], ['-'], ['-'], ['-']]]
It will still show each element as a list, as you defined it, if you want to show them as strings you'll have to use joins like m.wasowski suggests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With