[Tutor] one line code
alan.gauld at freenet.co.uk
alan.gauld at freenet.co.uk
Tue Apr 5 14:45:53 CEST 2005
>This is a perfect opportunity to give the reminder that the
>conversion
>functions are also types that can be used more transparently for such
Neat I didn't know\ that. How dioes Python equate a function object
to a type? Is it hard wired?
> >>> [(type(x)==int and float(x) or x) for x in l]
>['foo', 0]
> >>> # notice that 0 is still an int, not a float
> >>> [(type(x)==int and [float(x)] or [x])[0] for x in l]
>['foo', 0.0]
> >>> # ok, that's better
And a nice subtle catch.
Alan G.
More information about the Tutor
mailing list