Python: function to fetch data always returns None
Question: I have this list of dictionaries:

    
    
    cust = [
            {"id": 1, "name": u"name 1", "bill_amount": 1000},
            {"id": 2, "name": u"name 2", "bill_amount": 5000},
            {"id": 3, "name": u"name 3", "bill_amount": 7600},
            {"id": 4, "name": u"name 4", "bill_amount": 30}
           ]
    

And I want to get a list of just the names.

Trying this:

    
    
    def getName(x): x["name"]
    print map(getName, cust)
    

Returns this:

    
    
    [None, None, None, None]
    

Why? Am I missing something obvious?


Answer: You could also use
[`operator.itemgetter()`](http://docs.python.org/library/operator.html#operator.itemgetter)
instead of defining your own function for this:

    
    
    >>> import operator
    >>> map(operator.itemgetter("name"), cust)
    [u'name 1', u'name 2', u'name 3', u'name 4']
    

