4 ms·
Yeah I think having some a few more methods on some types would be nicer than having global functions like `map` for example, imagine if your example could be
by emptysea 3y ago
Yeah I think having some a few more methods on some types would be nicer than having global functions like `map`
for example, imagine if your example could be written as:
range(10).map(lambda x: x*2).list()
but as a list comprehension it's slightly shorter, but autocomplete isn't as good:
[x*2 for x in range(10)]
Also some historical context, Python's list comprehension are based on Haskell's
- pxc 3y agoFor whatever reason, having just the global functions feels more natural to me in Lisps, but weirder where function names precede the opening parentheses. I do also find the comprehensions more readable when one is actually using all of their components, i.e., when the function in the map behind the sugar would not be the identity function. But occasionally, when all the author really wanted to do is filter, you'll see stuff like [x for x in ... if ...] and that always strikes me as a bit weird and unfortunate. > Also some historical context, Python's list comprehension are based on Haskell's I didn't know that! I do kinda like Python's preference for English keywords over arrows here, even though the Haskell syntax is more concise or whatever.