464,359 Members | 1,282 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,359 IT Pros & Developers. It's quick & easy.

# list / index

 P: 4 let's say I have a list list1 = [0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,0,0,0,1,0] now I have another list list2 = [5,9,10] What I am trying to do is check the value of each index in list2, for that index in list1 i.e. list2, index(0), is 5, I want to check the value of the index(5) in list1 I was thinking a for loop with an if loop inside it, but I'm not sure how to call the corresponding index in the first list Feb 13 '12 #1

#### ✓ answered by bvdet

It's easier than that:
Expand|Select|Wrap|Line Numbers
1. >>> for item in list2:
2. ...     print "list1, index %d: %d" % (item, list1[item])
3. ...
4. list1, index 5: 0
5. list1, index 9: 0
6. list1, index 10: 0
7. >>>

2 Replies

 Expert Mod 2.5K+ P: 2,851 It's easier than that: Expand|Select|Wrap|Line Numbers >>> for item in list2: ...     print "list1, index %d: %d" % (item, list1[item]) ...      list1, index 5: 0 list1, index 9: 0 list1, index 10: 0 >>>  Feb 13 '12 #2

 P: 4 Ohh, wow, much more simple, thanks! Feb 13 '12 #3