[(eval(compile('exec """try:t=float("%s")\nexcept:t="%s" """ in
globals(),locals()'%(s,s),'','exec')),t)[1] for s in l]

Now that's ugly.



On Apr 5, 2005 9:51 AM, Alan Gauld <[EMAIL PROTECTED]> wrote:
> > 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.
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to