4 ms·
To perhaps shed a little light on the None thing and why it would be useful, consider the following: def munge(data, convert=None): data = map(conv
by ekimekim 11y ago
To perhaps shed a little light on the None thing and why it would be useful, consider the following:
def munge(data, convert=None):
data = map(convert, data)
...
ie. treating None as identity gives you sane default behaviour in the case that you want to optionally provide a mapping functionality. Granted, you can easily do an "if convert is not None" but I think this is slightly nicer.
Welp, add it to the list of things I think are better in py2 than py3.
- christianmann 11y agoOr you could do def munge(data, convert=lambda x: x)
- ah- 11y agoThis is C++ style thinking, but that way it has to copy the array and run that function on every element. If it supports none it can just return the original data.