Re: [Tutor] one line code

2005-04-06 Thread Christian Meesters
Hi, Great! My own solution was more like Wolfram's. But your solution, Pierre, really runs under "obfuscating enhanced". I like it. And your idea, Andrei, is something I really didn't expect. Anyway, sorry for my late reply. Guess I learned a lot again. Thanks, Christian

Re: [Tutor] one line code

2005-04-05 Thread Gregor Lingl
Pierre Barbier de Reuille schrieb: Mmmhhh ... not strictly one line but ... import re float_str = re.compile(r"^\s*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?\s*$") val = [ ( (float_str.match(s) and [float(s)]) or [s])[0] for s in l2 ] It's not really "readable" but well ... it works ^_^ Pierre This c

Re: [Tutor] one line code

2005-04-05 Thread Kent Johnson
Pierre Barbier de Reuille wrote: [EMAIL PROTECTED] a écrit : 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?

Re: [Tutor] one line code

2005-04-05 Thread Pierre Barbier de Reuille
[EMAIL PROTECTED] a écrit : 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? No, you see it the wrong way !

Re: [Tutor] one line code

2005-04-05 Thread alan . gauld
>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] >[

Re: [Tutor] one line code

2005-04-04 Thread C Smith
From: "Alan Gauld" <[EMAIL PROTECTED]> 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 ] This is a perfect opportunity to give the reminder that the conversion functions are also types tha

Re: [Tutor] one line code

2005-04-04 Thread Liam Clarke
[(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 ap

Re: [Tutor] one line code

2005-04-04 Thread Alan Gauld
> 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

Re: [Tutor] one line code

2005-04-04 Thread Pierre Barbier de Reuille
Mmmhhh ... not strictly one line but ... import re float_str = re.compile(r"^\s*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?\s*$") val = [ ( (float_str.match(s) and [float(s)]) or [s])[0] for s in l2 ] It's not really "readable" but well ... it works ^_^ Pierre Christian Meesters a écrit : Hi Yesterday

[Tutor] one line code

2005-04-04 Thread Christian Meesters
Hi Yesterday night I was thinking about the following problem: I do have a list like l = ['1','2','3','abc','','4'] - for instance like a list one could get from a file import with the csv module (which is where my 'problem' comes from). Now I would like to generate the following list, preferabl