[Tutor] one line code
cyresse at gmail.com
Tue Apr 5 00:40:25 CEST 2005
[(eval(compile('exec """try:t=float("%s")\nexcept:t="%s" """ in
globals(),locals()'%(s,s),'','exec')),t) for s in l]
Now that's ugly.
On Apr 5, 2005 9:51 AM, Alan Gauld <alan.gauld at freenet.co.uk> 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 at python.org
'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.
More information about the Tutor