Finding the indices of matching elements in list in Python

前端 未结 3 861
北荒
北荒 2020-11-30 00:09

I have a long list of float numbers ranging from 1 to 5, called \"average\", and I want to return the list of indices for elements that are smaller than a or larger than b

3条回答
  •  猫巷女王i
    2020-11-30 00:37

    >>> average =  [1,3,2,1,1,0,24,23,7,2,727,2,7,68,7,83,2]
    >>> matches = [i for i in range(0,len(average)) if average[i]<2 or average[i]>4]
    >>> matches
    [0, 3, 4, 5, 6, 7, 8, 10, 12, 13, 14, 15]
    

提交回复
热议问题