Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> a = [1,2,2,3,1,4,2]
- >>> val = 2
- >>> [index for index, data in enumerate(a) if data == val ]
- [1, 2, 6]
- >>> {index : val for index, data in enumerate(a) if data == val }
- {1: 2, 2: 2, 6: 2} # index will be unique so we can create it as key
Add Comment
Please, Sign In to add comment