4 ms·
Ok. Now consider what happens with slices/arrays instead of maps. 1) for k := range list {} 2) for k, i := range list {} In python, the equivalents are:
by candiodari 9y ago
Ok. Now consider what happens with slices/arrays instead of maps.
1) for k := range list {}
2) for k, i := range list {}
In python, the equivalents are:
1) for x in lst:
2) for x, y in enumerate(lst):
So are these "the same" ? No.
- Vendan 9y agomore accurately it's for index := range list {} and for index, value := range list {} Yes, these 2 version do perform very similarly, you are just ignoring the second return value in the first version, i.e.: for index, _ := range list {}