i am a beginner in python my wish is to make an array of n lines and n rows. I have a dictionnary of words and i need to put them in an array n*n . provisions ={'cake':'20','eggs':'10','tomatoes':'4','potatoes':'2','bread':'4'}
| / | 1 | 2 |
| 1 | cake | eggs |
| 2 | tomatoes | potatoes |
that is an example of what i want. we have here an array of 2 lines and 2 rows. i can have a dictionnary of more than 5 elements.That is just for an example.
import string
provisions = {'cake':'20','eggs':'10','tomatoes':'4','potatoes':'2','bread':'3'}
tab = []
#i can modify the n for having an array of n*n no matter if provisions has more elements
n = 2
j = 0
i = 0
if provisions:
for k,v in provisions.items():
while i<n:
while j<n:
print(f"{k}")
tab[[i],[j]] = provisions[i]
j += 1
i += 1