Reputation: 21
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
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