[Tutor] Fwd: Re: Doubt in Python
Alan Gauld
alan.gauld at yahoo.co.uk
Thu Jan 17 04:57:03 EST 2019
CCing the list. Please use Reply All or Reply List on responses to the list.
On 17/01/2019 07:24, Maninath sahoo wrote:
>>>> a=[100,50,30]
>>>> b=[100,90,3]
>>>> a<b
> True
>>>> a>b
> False
>
>
> How it compares between two lists
>
The algorithm is probably described somewhere in the documentation
but my understanding is that it looks something like this(in pdeudo code):
def isEqual(X,Y):
if len(X) != len(Y): return False
if X[0] != Y[0]: return False
return X[1:] == Y[1:]
def isGreater(X,Y):
if len(X) <= len(Y) return False
if X[0] < Y[0] return False
if X[0] == Y[0] return X[1:] > Y[1:]
return True
And similarly for the other operators.
But that's just based on playing with the interpreter and exploring
different values...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list