Q:

how to get list from a list which contains dict_values in python

I have a list which is having a set of key,values like 
      {`namelist = [{'name': 'John'},{'name': 'Tin'},{'name': 'Mony'}, 
                    {'name':'Hilber'},{'name': 'Marge'}]`}

Iam tring to get list which is having only names like
       {`names =['John','Tin','Mony','Hilber','Marge']`}

I tried like 
      {`names = []
         for i in range(len(namelist)):
           names.append(namelist[i].values())`}

it is giving output like
       {`[dict_values(['John']),
          dict_values(['Tin']),
          dict_values(['Mony']),
          dict_values(['Hilber']),
          dict_values(['Marge'])]
        `}

but i want only names in the list without dict_values tagging. please help me 

A:

You can use map from map-reduce (Please look for map-reduce in python for more details)
namelist = [{'name': 'John'},{'name': 'Tin'},{'name': 'Mony'}, 
                    {'name':'Hilber'},{'name': 'Marge'}]

result = map(lambda item: item.get('name'), namelist)
print(list(result))

In short map operation simply lets you map a collection of items into a different collection of items. It takes a function and at least one iterable as an argument. On each iteration, a single item is supplied to the function which must return a value. The value is collected which is of map type which can be converted using list().

