fork download
  1. def why(arr,elem):
  2. temp = min(arr,key=lambda x:abs(x-elem))
  3. return arr and [x for x,y in enumerate(arr) if y == temp] or None
  4.  
  5. a = [1,2,3,1,3,4,1,2,3,3]
  6. b = 3
  7. print why(a,b)
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
[2, 4, 8, 9]