[Tutor] list.index() question

Robert Berman bermanrl at cfl.rr.com
Thu Dec 8 22:33:53 CET 2011


On 12/08/2011 04:27 PM, bodsda at googlemail.com wrote:
> That won't work because l1[0] is ['a', 1]
>
> What happens if you don't change the code?
>
> l1.index('c')
>
> Bodsda
> Sent from my BlackBerry® wireless device
>
> -----Original Message-----
> From: Robert Berman<bermanrl at cfl.rr.com>
> Sender: tutor-bounces+bodsda=googlemail.com at python.org
> Date: Thu, 08 Dec 2011 16:13:32
> To: tutor<tutor at python.org>In [1]: l1=[['a',1],['b',2],['c',3]]
>
> In [2]: l1
> Out[2]: [['a', 1], ['b', 2], ['c', 3]]
>
> In [3]: l1.index('c')
> ---------------------------------------------------------------------------
> ValueError                                Traceback (most recent call last)
>
> /home/bermanrl/<ipython console>  in<module>()
>
> ValueError: 'c' is not in list
>
>
> Subject: [Tutor] list.index() question
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
Bodsa et al,

What happens is as follows:
In [1]: l1=[['a',1],['b',2],['c',3]]

In [2]: l1
Out[2]: [['a', 1], ['b', 2], ['c', 3]]

In [3]: l1.index('c')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/bermanrl/<ipython console> in <module>()

ValueError: 'c' is not in list


I really appreciate the help I am getting. Eventually I am certain there 
is a relatively easy solution I simply do not have the expertise to see it.

Robert


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111208/ce4190ed/attachment-0001.html>


More information about the Tutor mailing list