[Tutor] one line code

Alan Gauld alan.gauld at freenet.co.uk
Mon Apr 4 23:51:54 CEST 2005


> With other words I'd like to tell Python: Convert into a float if 
> possible, otherwise append anyway. 

[ (type(x) == type(5) and float(x) or x) for x in mylist ]

Should do it...

Alan G.


More information about the Tutor mailing list