Re: [Tutor] Accessing a tuple of a dictionary's value

2018-08-24 Thread Mats Wichmann
On 08/24/2018 03:02 AM, Alan Gauld via Tutor wrote: > CCing list, please always use Reply-All or Reply-List when responding > to the tutor list so that everyone gets a chance to reply. > > > On 24/08/18 00:35, Roger Lea Scherer wrote: >> >> Lots of code missing, but the line I'm interested in is

Re: [Tutor] Accessing a tuple of a dictionary's value

2018-08-24 Thread Alan Gauld via Tutor
On 24/08/18 10:02, Alan Gauld via Tutor wrote: > CCing list, please always use Reply-All or Reply-List when responding > to the tutor list so that everyone gets a chance to reply. > > > On 24/08/18 00:35, Roger Lea Scherer wrote: >> >> Lots of code missing, but the line I'm interested in is

Re: [Tutor] Accessing a tuple of a dictionary's value

2018-08-24 Thread Alan Gauld via Tutor
CCing list, please always use Reply-All or Reply-List when responding to the tutor list so that everyone gets a chance to reply. On 24/08/18 00:35, Roger Lea Scherer wrote: > > Lots of code missing, but the line I'm interested in is this: > print("Your numberĀ  " + str(numerator) + "/" +

Re: [Tutor] Accessing a tuple of a dictionary's value

2018-08-22 Thread Alan Gauld via Tutor
On 22/08/18 17:27, Mats Wichmann wrote: > I'm really unfond of accessing members of a collection by numeric index. > > >>> numer, denom = d["twothirds"] > >>> print(numer, denom) > (2, 3) > > I think that's nicer than: numer = d["twothirds][0] You can alsao avoid indexes with the

Re: [Tutor] Accessing a tuple of a dictionary's value

2018-08-22 Thread Mats Wichmann
On 08/21/2018 04:27 PM, Roger Lea Scherer wrote: > So I'm trying to divide fractions, technically I suppose integers. So, for > instance, when the user inputs a 1 as the numerator and a 2 as the > denominator to get the float 0.5, I want to put the 0.5 as the key in a > dictionary and the 1 and

Re: [Tutor] Accessing a tuple of a dictionary's value

2018-08-22 Thread Steven D'Aprano
On Tue, Aug 21, 2018 at 03:27:46PM -0700, Roger Lea Scherer wrote: > I want to put the 0.5 as the key in a > dictionary and the 1 and the 2 as the values of the key in a list {0.5: [1, > 2]}, hoping to access the 1 and 2 later, but not together. Let's do some experimentation. Here's a list: py>

Re: [Tutor] Accessing a tuple of a dictionary's value

2018-08-22 Thread Steven D'Aprano
On Tue, Aug 21, 2018 at 03:27:46PM -0700, Roger Lea Scherer wrote: > So I'm trying to divide fractions, technically I suppose integers. Python has a library for doing maths with fractions. Unfortunately it is considerably too complex to use as a learning example, but as a practical library for

Re: [Tutor] Accessing a tuple of a dictionary's value

2018-08-22 Thread Alan Gauld via Tutor
On 21/08/18 23:27, Roger Lea Scherer wrote: > I can't find anything in StackOverflow or Python documentation specifically > about this. They talk about accessing a list or a tuple or a dictionary, > but not when the value is a tuple or list. The value is irrelevant youi access the value in