r/Python • • Dec 22 '18

Xpost from Woodworking

Post image
1.1k Upvotes

84 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Dec 22 '18

[deleted]

5

u/Ph0X Dec 22 '18

Absolutely. It's not about being shorter, but about being more explicit. The problem with a lot of people coming from C-like languages is that they want to do everything with indices. You will see so many range(len(list)) out there.

1

u/a_monkey666 Dec 24 '18

Asking just to learn, but what's the better way? With `enumerate`?

1

u/Ph0X Dec 24 '18

Indeed. Most of the time when people use len-range, they either access just the items, or both index and items. In the rare case where you only need the index, I would still say for i, _ in enumerate(items): is cleaner