590 B
590 B
title, tags
| title | tags |
|---|---|
| pluck | list,dictionary,intemediary |
Extracts a list of values from a dict given a key
- Given an
arrayofdicts, returns the list of values of thekeypassed from each dict record. - When a dict does not have the
keypassed, returnsNone
def pluck(array, key):
return list(map(lambda entry: dict.get(entry, key), array))
simpsons = [
{ "name": "lisa", "age": 8 },
{ "name": "homer", "age": 36 },
{ "name": "marge", "age": 34 },
{ "name": "bart", "age": 10 },
];
pluck(simpsons, "age") # [8, 36, 34, 10]