Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61315
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <bsk16@case.edu> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.015 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'python,': 0.02; '21,': 0.07; 'subject:help': 0.08; '22,': 0.09; 'function,': 0.09; 'received:209.85.219': 0.09; 'python': 0.11; 'def': 0.12; 'programs.': 0.14; 'question.': 0.14; '12:59': 0.16; '[name': 0.16; 'lambda': 0.16; 'loop.': 0.16; 'shorthand': 0.16; 'subject:programming': 0.16; 'utc,': 0.16; 'subject:python': 0.16; 'language': 0.16; 'wrote:': 0.18; 'help.': 0.21; 'comfortable': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'pass': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'dec': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'asked': 0.31; 'code': 0.31; 'posting': 0.31; 'os,': 0.31; 'probably': 0.32; 'stuff': 0.32; 'run': 0.32; 'received:209.85': 0.35; 'december': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'doing': 0.36; 'thanks': 0.36; 'should': 0.36; 'list': 0.37; 'list.': 0.37; 'received:209': 0.37; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'tell': 0.60; "you're": 0.61; 'first': 0.61; 'back': 0.62; 'email addr:gmail.com': 0.63; 'name': 0.63; 'more': 0.64; '20,': 0.68; 'hoping': 0.75; 'age': 0.80; '10:32': 0.84; 'age.': 0.84; 'ages': 0.84; 'dic': 0.84; 'find.': 0.84; 'directly.': 0.95; '2013': 0.98 |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=du7djC/0lw2A0OUiLroE20toQoI2bUJ0dnXIdiyPKQs=; b=Y4ikkzxi8xWYreDz7iqJP+5m//y3Fb3jyCuqBWxVnOG/6LpajxXMcO47Wwu4IOde4s 0fgazpF5uMNs1H/PDMv66LcGmhOw56vRe1KPxkySy54osFQfjagC0ZuNd5QNE+S0Lo7W PS2G6sWvGyNjrVk9x49TrVak4Gm05S9Oru5h0nk/RB+1Wg6OpBbpLEnp67fK26KBmz7o wNWy5DBdHWcetswUC8He0nukjkmrHxia0v79InS24RNDFv1OUie+wXzrZ/gV1KQDAOZw zRlInM0wslw2DxnGD7T1MaZOMSDuh2iLUpnKdXX4HlFWpr88u8E3BsFuIrtPlPo9Q3gg CIrQ== |
| X-Gm-Message-State | ALoCoQl645pCsos8J2W1X+12vKpABJpk2vBTtnj/CUMAKq1RIM0I+rXpRL4s6Rg0F+OKO7AFVD1Q7AtA15+wjXd3WIq8b6I98hHej+wS6bdxK3PmgRVEnXkdo3Y04rOOBc7NsdiAlW92fOkl5QNEMqJfwtd9bU5LyA== |
| X-Received | by 10.182.230.135 with SMTP id sy7mr10266774obc.24.1386528752308; Sun, 08 Dec 2013 10:52:32 -0800 (PST) |
| X-Received | by 10.182.230.135 with SMTP id sy7mr10266768obc.24.1386528752156; Sun, 08 Dec 2013 10:52:32 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> |
| References | <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <mailman.3733.1386527267.18130.python-list@python.org> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> |
| From | Benjamin Kaplan <benjamin.kaplan@case.edu> |
| Date | Sun, 8 Dec 2013 10:52:12 -0800 |
| Subject | Re: python programming help |
| To | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-Junkmail-Whitelist | YES (by domain whitelist at mpv2.tis.cwru.edu) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3737.1386529135.18130.python-list@python.org> (permalink) |
| Lines | 68 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1386529135 news.xs4all.nl 2861 [2001:888:2000:d::a6]:33061 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:61315 |
Show key headers only | View raw
On Sun, Dec 8, 2013 at 10:32 AM, <rafaellasav@gmail.com> wrote:
>
> On Sunday, December 8, 2013 6:27:34 PM UTC, bob gailer wrote:
> > On 12/8/2013 12:59 PM, rafaellasav@gmail.com wrote:
> >
> > > 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
> >
> > Welcome to the python list. Thanks for posting a question.
> >
> >
> >
> > If you were hoping for one of us to write the program for you ... well
> >
> > that's not what we do on this list.
> >
> >
> >
> > Please post the code you have so far and tell us exactly where you need
> >
> > help.
> >
> >
> >
> > Also tell us what version of Python, what OS, and what you use to write
> >
> > and run Python programs.
>
> name = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', 'Gary', 'Helen', 'Irene', 'Jack', 'Kelly', 'Larry']
> age = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19]
> dic={}
> def combine_lists(name,age):
> for i in range(len(name)):
> dic[name[i]]= age[i]
> combine_lists(name,age)
> print dic
>
> def people(age):
> people=lambda age: [name for name in dic if dic[name]==age]
>
> people(20)
>
>
>
>
> this is the code i have so far(with the help of the first post ;p). i understand how a function and a dictionary works and what I'm asked to find. but i don't get the lambda age part. and this code doesn't give me any result
>
>
To return a value from a function, you need to use the "return"
statement with the value you want to pass back out. You're not doing
that here. Also, you're using a lot of shorthand stuff that you should
probably avoid until you're more comfortable with the language
* Lambda is shorthand for a function. foo = lambda bar : bar + 2 is
the same thing as the function
def foo(bar) :
return bar + 2
* a list comprehension is short-hand for a loop. spam = [foo for foo
in bar if baz(foo)] is the same thing as
spam = []
for foo in bar :
if baz(foo) :
spam.append(foo)
You don't need a lambda here- just call the code that you need to call directly.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
python programming help rafaellasav@gmail.com - 2013-12-08 09:59 -0800
Re: python programming help YBM <ybmess@nooos.fr.invalid> - 2013-12-08 19:07 +0100
Re: python programming help rafaellasav@gmail.com - 2013-12-08 10:14 -0800
Re: python programming help YBM <ybmess@nooos.fr.invalid> - 2013-12-08 19:18 +0100
Re: python programming help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-08 18:25 +0000
Re: python programming help Christopher Welborn <cjwelborn@live.com> - 2013-12-09 17:34 -0600
Re: python programming help Roy Smith <roy@panix.com> - 2013-12-08 13:23 -0500
Re: python programming help Gary Herron <gary.herron@islandtraining.com> - 2013-12-08 10:20 -0800
Re: python programming help bob gailer <bgailer@gmail.com> - 2013-12-08 13:27 -0500
Re: python programming help rafaellasav@gmail.com - 2013-12-08 10:32 -0800
Re: python programming help rafaellasav@gmail.com - 2013-12-08 10:42 -0800
Re: python programming help Benjamin Kaplan <benjamin.kaplan@case.edu> - 2013-12-08 10:52 -0800
Re: python programming help rafaellasav@gmail.com - 2013-12-08 11:06 -0800
Re: python programming help Chris Angelico <rosuav@gmail.com> - 2013-12-09 06:17 +1100
Re: python programming help rurpy@yahoo.com - 2013-12-08 16:08 -0800
Re: python programming help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-09 00:27 +0000
Re: python programming help rurpy@yahoo.com - 2013-12-08 21:07 -0800
Re: python programming help rusi <rustompmody@gmail.com> - 2013-12-08 21:20 -0800
Re: python programming help rurpy@yahoo.com - 2013-12-09 21:15 -0800
Re: python programming help Chris Angelico <rosuav@gmail.com> - 2013-12-09 18:57 +1100
Re: python programming help rurpy@yahoo.com - 2013-12-09 21:07 -0800
Re: python programming help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-09 09:34 +0000
Meta Fight About Posting (was: python programming help) Travis Griggs <travisgriggs@gmail.com> - 2013-12-09 07:44 -0800
Re: Meta Fight About Posting (was: python programming help) rusi <rustompmody@gmail.com> - 2013-12-09 08:25 -0800
Re: Meta Fight About Posting (was: python programming help) rusi <rustompmody@gmail.com> - 2013-12-09 08:47 -0800
Re: Meta Fight About Posting (was: python programming help) Roy Smith <roy@panix.com> - 2013-12-09 13:48 -0500
Re: Meta Fight About Posting (was: python programming help) Roy Smith <roy@panix.com> - 2013-12-09 13:45 -0500
Re: python programming help Chris Angelico <rosuav@gmail.com> - 2013-12-09 14:05 +1100
Re: python programming help rurpy@yahoo.com - 2013-12-08 21:10 -0800
Re: python programming help Joel Goldstick <joel.goldstick@gmail.com> - 2013-12-09 00:22 -0500
Re: python programming help Chris Angelico <rosuav@gmail.com> - 2013-12-09 19:15 +1100
Re: python programming help rurpy@yahoo.com - 2013-12-09 21:10 -0800
Re: python programming help Chris Angelico <rosuav@gmail.com> - 2013-12-10 16:29 +1100
Re: python programming help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-08 19:21 +0000
Re: python programming help Terry Reedy <tjreedy@udel.edu> - 2013-12-08 16:17 -0500
Re: python programming help YBM <ybmess@nooos.fr.invalid> - 2013-12-09 03:02 +0100
Re: python programming help John Ladasky <john_ladasky@sbcglobal.net> - 2013-12-08 11:21 -0800
Re: python programming help Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-09 13:00 +1300
Re: python programming help YBM <ybmess@nooos.fr.invalid> - 2013-12-09 02:51 +0100
Re: python programming help YBM <ybmess@nooos.fr.invalid> - 2013-12-09 03:31 +0100
csiph-web