By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,550 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,550 IT Pros & Developers. It's quick & easy.

index in "double" list

P: n/a
Hello!

I have a list of lists (e.g. [[1,"a"],[2,"b"],[3,"c"]]) and
would like to do index on the first element of the lists.
Can it be done?

B.

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
If you have list:

t=[[1,"a"],[2,"b"],[3,"c"]]

The first element of each list contained
in t is accessed by:

t[n][0]

where n is the element number you wish to access
(zero based of course).

-Larry

"Boštjan Jerko" <bo***********@mf.uni-lj.si> wrote in message
news:ma***************************************@pyt hon.org...
Hello!

I have a list of lists (e.g. [[1,"a"],[2,"b"],[3,"c"]]) and
would like to do index on the first element of the lists.
Can it be done?

B.

Jul 18 '05 #2

P: n/a
Bo?tjan Jerko <bo***********@mf.uni-lj.si> wrote in message news:<ma***************************************@py thon.org>...
Hello!

I have a list of lists (e.g. [[1,"a"],[2,"b"],[3,"c"]]) and
would like to do index on the first element of the lists.
Can it be done?


I think you might want to try using dicts.
d = {1: 'a', 2: 'b', 3: 'c'}
d[2] 'b'

If you already have a list of lists, you can convert it to a dict with
the constructor.
a = [[1, "a"], [2, "b"], [3, "c"]]
d = dict(a)

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.