Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99307
| X-Received | by 10.107.4.81 with SMTP id 78mr16901216ioe.18.1448360864036; Tue, 24 Nov 2015 02:27:44 -0800 (PST) |
|---|---|
| X-Received | by 10.50.97.38 with SMTP id dx6mr415903igb.9.1448360864021; Tue, 24 Nov 2015 02:27:44 -0800 (PST) |
| Path | csiph.com!au2pb.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.glorb.com!mv3no1251597igc.0!news-out.google.com!f6ni11933igq.0!nntp.google.com!mv3no1251596igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Tue, 24 Nov 2015 02:27:43 -0800 (PST) |
| In-Reply-To | <mailman.98.1448360068.2291.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=2404:e800:ee12:41:176:65de:97af:4cfe; posting-account=V6fVrwoAAAB_KNNhh7gdmvqhYlmrIkSO |
| NNTP-Posting-Host | 2404:e800:ee12:41:176:65de:97af:4cfe |
| References | <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> <mailman.98.1448360068.2291.python-list@python.org> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <45b60b80-d6b7-423e-93b9-2ef4977fb368@googlegroups.com> (permalink) |
| Subject | Re: Returning a result from 3 items in a list |
| From | Cai Gengyang <gengyangcai@gmail.com> |
| Injection-Date | Tue, 24 Nov 2015 10:27:44 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:99307 |
Show key headers only | View raw
Strange, it gives me an error message when i type result["jordan"] or result[max(result)] though :
>>> results = {
"gengyang": 14,
"ensheng": 13,
"jordan": 12
}
>>> result["jordan"]
Traceback (most recent call last):
File "<pyshell#27>", line 1, in <module>
result["jordan"]
NameError: name 'result' is not defined
>>> result[max(result)]
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
result[max(result)]
NameError: name 'result' is not defined
>>>
On Tuesday, November 24, 2015 at 6:14:43 PM UTC+8, Chris Angelico wrote:
> On Tue, Nov 24, 2015 at 9:04 PM, Cai Gengyang <gengyangcai@gmail.com> wrote:
> > Here's a dictionary with 3 values :
> >
> > results = {
> > "gengyang": 14,
> > "ensheng": 13,
> > "jordan": 12
> > }
> >
> > How do I define a function that takes the last of the 3 items in that list and returns Jordan's results i.e. (12) ?
> >
> > Thanks a lot !
>
> If you want Jordan's result, that's easy:
>
> result["jordan"]
>
> But there's no concept of "the last" entry in a dict. They don't have
> an order. Do you mean "the entry with the greatest key"? That could be
> written thus:
>
> result[max(result)]
>
> because max(result) is the string "jordan".
>
> Does either of those make sense for what you're doing?
>
> ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Returning a result from 3 items in a list Cai Gengyang <gengyangcai@gmail.com> - 2015-11-24 02:04 -0800
Re: Returning a result from 3 items in a list Chris Angelico <rosuav@gmail.com> - 2015-11-24 21:14 +1100
Re: Returning a result from 3 items in a list Cai Gengyang <gengyangcai@gmail.com> - 2015-11-24 02:27 -0800
Re: Returning a result from 3 items in a list Peter Otten <__peter__@web.de> - 2015-11-24 11:35 +0100
Re: Returning a result from 3 items in a list Cai Gengyang <gengyangcai@gmail.com> - 2015-11-24 02:47 -0800
Re: Returning a result from 3 items in a list Chris Angelico <rosuav@gmail.com> - 2015-11-24 22:05 +1100
Re: Returning a result from 3 items in a list Cai Gengyang <gengyangcai@gmail.com> - 2015-11-24 03:06 -0800
Re: Returning a result from 3 items in a list Peter Otten <__peter__@web.de> - 2015-11-24 11:32 +0100
Re: Returning a result from 3 items in a list Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-24 14:07 +0000
Re: Returning a result from 3 items in a list Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-11-24 14:28 +0000
Re: Returning a result from 3 items in a list Ned Batchelder <ned@nedbatchelder.com> - 2015-11-24 08:59 -0800
Re: Returning a result from 3 items in a list Cai Gengyang <gengyangcai@gmail.com> - 2015-11-25 02:26 -0800
Re: Returning a result from 3 items in a list Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-11-25 11:22 +0000
csiph-web