hardikudeshi - 1 year ago 88

Python Question

I have a list say

`a = [5,3,1,4,10]`

Answer Source

```
sorted(range(len(a)), key=lambda i: a[i])[-2:]
```

or

```
sorted(range(len(a)), key=lambda i: a[i], reverse=True)[:2]
```

or

```
zip(*sorted(enumerate(a), key=operator.itemgetter(1)))[0][-2:]
```

or (for long lists)

```
zip(*heapq.nlargest(2, enumerate(a), key=operator.itemgetter(1)))[0]
```