Re: Returning a result from 3 items in a list

2015-11-25 Thread Cai Gengyang
Programming is indeed tough ... I wish I had picked up this skill much earlier in life. But true, I will try to research my questions more in depth before posting here. My goal eventually is to build a successful YCombinator based web-based startup. On Wednesday, November 25, 2015 at

Re: Returning a result from 3 items in a list

2015-11-25 Thread Mark Lawrence
On 25/11/2015 10:26, Cai Gengyang wrote: But true, I will try to research my questions more in depth before posting here. Please also research how to intersperse your answers or bottom post. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our

Re: Returning a result from 3 items in a list

2015-11-24 Thread Ned Batchelder
On Tuesday, November 24, 2015 at 9:29:30 AM UTC-5, Mark Lawrence wrote: > On 24/11/2015 14:07, Denis McMahon wrote: > > On Tue, 24 Nov 2015 02:04:56 -0800, Cai Gengyang wrote: > > > >> Here's a dictionary with 3 values : > >> > >> results = { > >>"gengyang": 14, > >>"ensheng": 13,

Returning a result from 3 items in a list

2015-11-24 Thread Cai Gengyang
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 ! Gengyang --

Re: Returning a result from 3 items in a list

2015-11-24 Thread Peter Otten
Cai Gengyang 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 ! You can access the

Re: Returning a result from 3 items in a list

2015-11-24 Thread Peter Otten
Cai Gengyang wrote: > 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 "", line 1,

Re: Returning a result from 3 items in a list

2015-11-24 Thread Cai Gengyang
Yup, thanks a lot ... it works now ! >>> results = { "gengyang": 14, "ensheng": 13, "jordan": 12 } >>> results["jordan"] 12 On Tuesday, November 24, 2015 at 6:40:26 PM UTC+8, Peter Otten wrote: > Cai Gengyang wrote: > > > Strange, it gives me an error message when i type

Re: Returning a result from 3 items in a list

2015-11-24 Thread Chris Angelico
On Tue, Nov 24, 2015 at 9:04 PM, Cai Gengyang 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

Re: Returning a result from 3 items in a list

2015-11-24 Thread Cai Gengyang
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 "", line 1, in result["jordan"] NameError:

Re: Returning a result from 3 items in a list

2015-11-24 Thread Denis McMahon
On Tue, 24 Nov 2015 02:04:56 -0800, Cai Gengyang 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) ? You

Re: Returning a result from 3 items in a list

2015-11-24 Thread Mark Lawrence
On 24/11/2015 14:07, Denis McMahon wrote: On Tue, 24 Nov 2015 02:04:56 -0800, Cai Gengyang 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

Re: Returning a result from 3 items in a list

2015-11-24 Thread Cai Gengyang
Its cool ... No problem On Tuesday, November 24, 2015 at 7:05:25 PM UTC+8, Chris Angelico wrote: > On Tue, Nov 24, 2015 at 9:35 PM, Peter Otten <__pete...@web.de> wrote: > > Yeah, the error message really should be > > > > "NameError: name 'result' is not defined; did you mean 'results'?" > > >

Re: Returning a result from 3 items in a list

2015-11-24 Thread Chris Angelico
On Tue, Nov 24, 2015 at 9:35 PM, Peter Otten <__pete...@web.de> wrote: > Yeah, the error message really should be > > "NameError: name 'result' is not defined; did you mean 'results'?" > > ;) Heh. Yes, that was my fault. Sorry Cai! it should have been results["jordan"], as you figured out.