[Tutor] Re: one line code

2005-04-05 Thread Andrei
Alan Gauld freenet.co.uk> writes: > > 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 ] Almost fell for it too, but the original list contains numbers stored as strings :).

[Tutor] Re: one line code

2005-04-04 Thread Andrei
Christian Meesters wrote on Mon, 4 Apr 2005 14:49:28 +0200: > Could it be that a C-like solution with > '?' and ':' is more straightforward than a solution with Python or am I > just too blind to see a real pythonic solution here? Pierre did the Python equivalent of the ternary operator in his

[Tutor] Re: one line code

2005-04-04 Thread Wolfram Kraus
Christian Meesters wrote: 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 fo