4 ms·
It's just plain wrong. For example, next() is a builtin function which mutates the iterator passed to it. And, in general, given that Python doesn't have extens
by int_19h 1y ago
It's just plain wrong. For example, next() is a builtin function which mutates the iterator passed to it. And, in general, given that Python doesn't have extension methods or anything similar, if you want to write a helper that works on mutable objects of some type, it'll have to be a free function.
- Spivak 1y agonext() is just sugar for iter.__next__() A common case where you would have a free function which mutates its parameter would be a function which takes a file handle but it's also the case that you wouldn't have a mutable default for this value.
- int_19h 1y agoIt doesn't change the fact that it's a function that mutates its parameter, even if it eventually calls a method to do so. And, furthermore, it is idiomatic to call next(iter) rather than iter.__next__(), even when no default value is expected.