Calvelo Daniel dcalvelo at pharion.univ-lille2.fr
Fri Sep 1 12:26:33 CEST 2000

skeetor <skeetornospam at bellsouth.net> wrote:
: I am trying to compare an input number with several numbers in a list, and
: then to print the range of that number. for example:  I have it ask for a
: number, and i reply with 4.  I want it to check to see if 4 is in the list
: and if so print the range.   I have solved the problem by writing out the
: argument for each number in the list... but it is very long.   I hope i have
: explained this accurately.  and please i am still a retarded four year
: old... so talk slowely and use small words.  thanks.

It's built into lists.

>>> a = [ 3, 1, 4, 1, 5, 9, 2, 6 ]
>>> a.index( 1 )
>>> a.index( 9 )
>>> a[ a.index( 4 ) ]

Read the tutorial in parallel to whatever you are doing. Even if you don't 
get it exactly, at least you will have a vague idea of the possibilities.


-- Daniel Calvelo Aros
     calvelo at lifl.fr

More information about the Python-list mailing list