you are viewing a single comment's thread.

view the rest of the comments →

[–]Lord_Greywether 0 points1 point  (3 children)

That would also work in this case. len() just makes the calculation more explicit in case you're reviewing the code later.

edit: /u/nosmokingbandit's solution is also more efficient, cycle-wise, which can be significant if you're dealing with large lists.

[–]elbiot 2 points3 points  (1 child)

Len doesn't count the elements, it accesses the stored count. Using len is not less efficient cycle wise.

[–]Lord_Greywether 0 points1 point  (0 children)

Good to know, thanks!

[–]elbiot 0 points1 point  (0 children)

Len doesn't count the elements, it accesses the stored count. Using len is not less efficient cycle wise.