DEV Community

Discussion on: 8 Coolest Python Programming Language Features

Collapse
 
elfjes profile image
Pelle Koster

Negative indexing is great. Not only for the -1: give me the last item, but also for -2: give me the second to last value. Also: it auto-wraps around. List of length 3? Index -4 brings you right back to the end. Great alternative for % (modulo) indexing and/or itertools.cycle. Be careful though, it might not make your code more readable, so be sure to express intent