On 1月13日, 下午8时32分, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> Use lambda when it works better for you, the speed difference is
> marginal in practice anyway. itemgetter is not (and was never
> intended to be) a general substitute for functions, as you've
> discovered.
>
> The marginal speed differ
lotrpy <[EMAIL PROTECTED]> writes:
> if i want sort each line by the first part,(it's a integer, in fact).
> don't know how to do it with itemgetter.
> key = int(itemgetter(0)) is wrong, key = lambda x:int(x[0]) works.
> but s.b. told me itemgetter execute more quickly .
Use lambda when it works
lotrpy wrote:
> key = int(itemgetter(0)) is wrong, key = lambda x:int(x[0]) works.
> but s.b. told me itemgetter execute more quickly .
so you're more interested in speed than in correctness? ;-)
operator.itemgetter is a function factory that creates a *function* that
fetches the given item fr