list / index

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • James Carpenter
    New Member
    • Feb 2012
    • 4

    list / index

    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
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    It's easier than that:
    Code:
    >>> for item in list2:
    ... 	print "list1, index %d: %d" % (item, list1[item])
    ... 	
    list1, index 5: 0
    list1, index 9: 0
    list1, index 10: 0
    >>>

    Comment

    • James Carpenter
      New Member
      • Feb 2012
      • 4

      #3
      Ohh, wow, much more simple, thanks!

      Comment

      Working...