3 ms·
The never use map/filter is in favor of list comprehensions, which is not really a OOP construct. But sure, it's a conventional thing. And for a long time the
by jononor 8y ago
The never use map/filter is in favor of list comprehensions, which is not really a OOP construct.
But sure, it's a conventional thing. And for a long time the built-in alternatives to a class for such a datastructure tuples and dicts, neither which are very nice for functions to operate on (dict values have to be addressed with d['key'] instead of d.key).
With a class and method there is also no doubt as to what the function operates on, which is convenient when there type hints and IDE support is missing. This is changing since Python 3.5 and type checking tools like MyPy.
Since Python 3.7 there are also data classes, a primitive for classes which just hold values. https://www.linuxjournal.com/content/introducing-python-37s-dataclasses https://www.linuxjournal.com/content/introducing-python-37s-...
But it will take a while before programming conventions change.