How to index elements in a list