3 ms·
You can use the zip function to loop through 2 collections. `for (l, r) in zip(c1, c2) {` It is not simply motivated by making code concise, I would say `for
by joewillsher 10y ago
You can use the zip function to loop through 2 collections.
`for (l, r) in zip(c1, c2) {`
It is not simply motivated by making code concise, I would say `for num in collection.reverse()` is less error prone and clearer than `for (var i = collection.count; i >= 0; i--) { var num = collection[i] ... }`
The reverse collection iterator is computed lazily too, so there is no little perf overhead
- bluecalm 10y agoSometimes having those counting variables available is needed. You can use enumerate now but it introduces a lot of noise as now everything is a tuple with a number. It just makes expressing some algorithms messier and less readable although in general for sure "new style" loop is more readable and less bug prone.