Re:The fate of reduce() in Python 3000 (2005)
by raverbashing on Tuesday January 01, 2019 @05:52PM
(#18802929)
Yeah, I don't get the "hate" for the functional operations, though comprehensions have better syntax
And no, I don't want to 'def' every small function I might need, pep-8 recommendations aside. Key as mentioned is one use, but there are other cases where it's especially useful
Re:The fate of reduce() in Python 3000 (2005)
by nszceta on Tuesday January 01, 2019 @02:33PM
(#18801790)
itemgetter and attrgetter are compiled C functions called by cpython https://github.com/python/cpython/blob/master/Modules/_opera...
Re:The fate of reduce() in Python 3000 (2005)
by masklinn on Tuesday January 01, 2019 @02:43PM
(#18801838)
They mean faster to write, not that it's necessarily faster to execute (though the difference is likely immaterial).
Re:The fate of reduce() in Python 3000 (2005)
by thomasahle on Tuesday January 01, 2019 @02:34PM
(#18801795)
Right, though for those uses something like the swift {$0[0]} or haskell (!!0) just seems a lot more of convenient.
By far the most common use of lambda for me is the "key" argument for sort() or sorted(). As in something like:
foo.sort(key=lambda x:x[2])
Yes, there are itemgetter and attrgetter in operator module, but I always have to look up their names and writing the lambda expression is simply faster.