M Chery
M Chery

Reputation: 21

How is code reading the multi-array to output such a format

groups = [["Roy","Sam","Amy"],["Tom","Jerry"]]

Trying to understand the output I am getting from this code

for group in groups: 
  for name in group: 
     print(group)

['Roy', 'Sam', 'Amy']
['Roy', 'Sam', 'Amy']
['Roy', 'Sam', 'Amy']
['Tom', 'Jerry']
['Tom', 'Jerry']

Upvotes: 0

Views: 22

Answers (1)

Mureinik
Mureinik

Reputation: 311113

Seems like you meant to print name (the element in the inner-list), not group (the inner-list itself):

>>> groups = [["Roy","Sam","Amy"],["Tom","Jerry"]]
>>> for group in groups: 
...     for name in group:
...             print(name)
... 
Roy
Sam
Amy
Tom
Jerry

Upvotes: 1

Related Questions