0
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']
1
  • 2
    Try print(name) instead of print(group) - you're not printing what you intended to print. Commented May 19, 2017 at 18:56

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.