Le 08.12.2013 19:14, rafaella...@gmail.com a écrit :
On Sunday, December 8, 2013 6:07:47 PM UTC, YBM wrote:
Le 08.12.2013 18:59, rafaella...@gmail.com a �crit :
i have a dictionary with names and ages for each name.
I want to write a function that takes in an age and returns
the names of all the people who are that age.
please help
ageDict = { 'john':42, 'jane':36, 'paul':42 }
peopleWithAge = lambda age: [ name for name in ageDict if
ageDict[name]==age]
sorry but i'm new to python ;p
1. it has to be in a form of a function called people and
2. how this code takes in an age and returns the names?
>>> ageDict = { 'john':42, 'jane':36, 'paul':42 }
>>> people = lambda age: [ name for name in ageDict if
... ageDict[name]==age]
>>> people(42)
['paul', 'john']
--
https://mail.python.org/mailman/listinfo/python-list