itemgetter with default arguments

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri May 4 22:15:22 EDT 2018


On 2018年5月04日 15:27:16 +0200, Antoon Pardon wrote:
>> I might be slow today, but I cannot see how to write a clear, obvious,
>> efficient lambda that provides functionality equivalent to itemgetter
>> with a default value.
[...]
> This seems to work:
>> f = (lambda seq: (list(seq) + 3 * ["spam"])[2])

Yep, I'm definitely slow today. Thanks for that.
Of course, it's also pretty slow, nearly as slow as me :-) On my 
computer, it was about 2000% slower than itemgetter using a moderate 
sized list (100 items).
-- 
Steve


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /