i'm porting code python 2.7 3. 2to3 not convert following lines , can't seem figure out. appreciated.
subpaths.sort( lambda x, y : int(pyx.unit.tocm(x.arclen() - y.arclen()) / math.fabs(pyx.unit.tocm(x.arclen() - y.arclen()))) )
the sort
method of list
requires key
, function of 1 argument. need convert lambda function function of single argument. there shortcut provided functools.cmp_to_key
. thus, need is:
import functools subpaths.sort(key=functools.cmp_to_key(lambda x, y: ...))
note if understand code correctly, can sort list using following key:
subpaths.sort(key=lambda x: pyx.unit.tocm(x.arclen()))
Comments
Post a Comment