Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99306
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Returning a result from 3 items in a list |
| Date | Tue, 24 Nov 2015 21:14:19 +1100 |
| Lines | 28 |
| Message-ID | <mailman.98.1448360068.2291.python-list@python.org> (permalink) |
| References | <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de vZiFxz+4HQyZquLJr7IHswiaxA9AVFQL/5aMkhxlU0MA== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.016 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'received:209.85.223': 0.03; 'cc:addr:python-list': 0.09; '24,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'string': 0.17; 'result,': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'written': 0.24; 'header:In-Reply- To:1': 0.24; 'subject:list': 0.26; 'sense': 0.26; 'define': 0.27; 'order.': 0.27; 'message-id:@mail.gmail.com': 0.27; '14,': 0.27; 'function': 0.28; 'values': 0.28; '13,': 0.29; 'dictionary': 0.29; 'doing?': 0.29; 'entry': 0.31; '"the': 0.32; 'tue,': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'i.e.': 0.35; 'nov': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:209': 0.38; 'mean': 0.38; 'does': 0.39; 'subject:from': 0.39; 'takes': 0.39; 'results': 0.66; 'chrisa': 0.84; 'dict.': 0.84; 'to:none': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=KPmvvxy8388fZri08f7CEK5+7Qmxvqygmk66tYvHrWU=; b=MrHP51FPugSXoLANNycazFc4reDTzN/J6Bsoqnf6fuGaY5DswsExo08m0dmzev/mqX cs9SeRIK6cM6+TyeGwgndNvp9Whthnc/qg3qCxJvqcoqkGLnLAlIEmmNp5WYu2zeqIju vP3M30gPVF8f8Zz0739sGnVOGBeL++sVDfWC8q9nmr57CiSESMWSFhCcMWBCTMl3db9u dzz+Ah2iuuJyY7iBugvAj4As4M8QP/uIS71JqjoBciH0EuDXNzDLZ2QwrNYJG54M5ka1 hzECYGrt/aZEjJrG4ICNzj+4s6+XQYJ4NN4KY3uNs+MztnYP14eUKSosDCUljWIEPeW8 fTIg== |
| X-Received | by 10.107.16.84 with SMTP id y81mr27328115ioi.19.1448360059933; Tue, 24 Nov 2015 02:14:19 -0800 (PST) |
| In-Reply-To | <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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> |
| Xref | csiph.com comp.lang.python:99306 |
Show key headers only | View raw
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