-1

I have a list of simple key value pair dictionaries. I want to return all the values

eg.

namelist([ {'name': 'Bart'}, {'name': 'Lisa'}, {'name': 'Maggie'} ])
# returns 'Bart, Lisa & Maggie'

whats the solution to this?

I do not understand how to do this. first I have just tried looping through to return each value in the list and it only returns the first item.

def namelist(names):
    for i in names:
        return i

It only returns:

{name: 'Bart'}

The end result should return: 'Bart, Lisa & Maggie'

I dont even understand why my loop isnt looping through each item in the list, just the first.

cs95
  • 379,657
  • 97
  • 704
  • 746
Ben Smith
  • 360
  • 4
  • 14

1 Answers1

-1

you're returning which exits the function. Just use print

Ahmed
  • 120
  • 6