Michael
Michael

Reputation: 16142

Print list inside two other lists in python 2.7

Here is my list:

index = [['you', ['http://you.com', 'http://you.org']], ['me', ['http://me.org']]]

How can I print a list that inside of the 'you' list?

I have tried to do this way:

>>>print index[0]

but it's printing out full 'you' list:

['you', ['http://you.com', 'http://you.org']]

and the output I need is:

['http://you.com', 'http://you.org']

Upvotes: 0

Views: 5932

Answers (2)

Micke
Micke

Reputation: 2309

As index[0] returns the first item in index, index[0][1] will return the second item within the first item:

>>> index = [['you', ['http://you.com', 'http://you.org']], ['me', ['http://me.org']]]
>>> index[0]
['you', ['http://you.com', 'http://you.org']]
>>> index[0][1]
['http://you.com', 'http://you.org']

In addition, if you have the time, spend some of it getting familiar with python data structures. You won't regret it.

Upvotes: 2

Talvalin
Talvalin

Reputation: 7889

You've got a list within a list, so you need to specify a second index ie

print index[0][1]

Upvotes: 7

Related Questions