Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find indexes on two lists based on items condition

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.

like image 464
Mike Avatar asked Apr 12 '12 17:04

Mike


1 Answers

>>> [i for i, v in enumerate(list1) if v>=1 and list2[i]==0]
[1, 2, 4, 14, 18, 27, 39, 48, 52]
like image 120
Praveen Gollakota Avatar answered Oct 21 '22 02:10

Praveen Gollakota