Find indexes on two lists based on item status

advertisements

Lets say I have two lists. They are lists of ratings of books on a scale from -5, to 5.

I want to know when list1's element is >= 1 and list2's element == 0, so for example.

list1 = [3, 3, 1, 0, 3, 0, 3, 0, 0, -3, 0, 5, 3, 0, 1, 0, 0, 5, 3, 0, 0, 0, 0, 1, 0, 3, 0, 1, 0, 0, 3, 5, 3, 3, 0, 0, 0, 5, 0, 5, 0, 3, 3, 0, -3, 0, 0, 5, 1, 5, 3, 0, 3, 0, 0]
list2 = [5, 0, 0, 0, 0, 0, 5, 0, 0, 1, 0, 5, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 5, 0, 0, 0, 0, 5, 5, 5, 3, 0, 0, 0, 3, 0, 0, 0, 5, 3, 0, 0, 0, 0, 5, 0, 5, 3, 0, 0, 0, 0]

list1[1] = 3 and list2[1] = 0, I want to be able to find all the different indexes of where this happens at.

Sorry if this is confusing but I don't really know how else to word this.


>>> [i for i, v in enumerate(list1) if v>=1 and list2[i]==0]
[1, 2, 4, 14, 18, 27, 39, 48, 52]