python programming help

Gregory Ewing greg.ewing at canterbury.ac.nz
Mon Dec 9 01:00:38 CET 2013


rafaellasav at gmail.com wrote:

> def people(age):
>     people=lambda age: [name for name in dic if dic[name]==age]
> 
> but i don't get the lambda age part.

Just to explain: YBM has tried to sabotage you by posting a
solution that uses a couple of advanced Python features
(lambda and list comprehensions) that a beginner would be
unlikely to know about. The idea is that if you had simply
handed that code in as-is, your teacher would know that you
had almost certainly not written it yourself.

Anyhow, you seem to be almost there. The only thing now
is that your function needs to *return* the result instead
of printing it out. To illustrate with a different example,
you currently have a function like this:

    def add(a, b):
       print a + b

This is fine as far as it goes, but the drawback is that
printing out the result is all it will ever do. You're
being asked to write a function like this:

    def add(a, b):
       return a + b

This is much more useful, because you can do anything you
like with the result, e.g.

    print add(2, 3) * add(4, 5)

-- 
Greg



More information about the Python-list mailing list