Re: List of strings to list of floats ?

2005-10-18 Thread Alex Martelli
Madhusudan Singh <[EMAIL PROTECTED]> wrote: ... > >> Say I have two lists of floats. And I wish to generate a list of floats > >> that is a user defined function of the two lists. > > > > result = [sqrt(x**2 + y**2) for x, y in zip(xs, ys)] > > Works perfectly. Thanks ! If zip works and map d

Re: List of strings to list of floats ?

2005-10-17 Thread bearophileHUGS
Erik Max Francis: >result = [sqrt(x**2 + y**2) for x, y in zip(xs, ys)] Another possibility: from math import hypot result = [hypot(*xy) for xy in zip(xs, ys)] Or better: from math import hypot result = map(hypot, xs, ys) bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: List of strings to list of floats ?

2005-10-17 Thread Madhusudan Singh
Erik Max Francis wrote: > Madhusudan Singh wrote: > >> Thanks. Now, a slightly more complicated question. >> >> Say I have two lists of floats. And I wish to generate a list of floats >> that is a user defined function of the two lists. > > result = [sqrt(x**2 + y**2) for x, y in zip(xs, ys)] >

Re: List of strings to list of floats ?

2005-10-17 Thread Erik Max Francis
Madhusudan Singh wrote: > Thanks. Now, a slightly more complicated question. > > Say I have two lists of floats. And I wish to generate a list of floats that > is a user defined function of the two lists. result = [sqrt(x**2 + y**2) for x, y in zip(xs, ys)] -- Erik Max Francis && [EMAI

Re: List of strings to list of floats ?

2005-10-17 Thread Madhusudan Singh
Steve Holden wrote: > Madhusudan Singh wrote: >> [EMAIL PROTECTED] wrote: >> >> >>>Madhusudan> Is it possible to convert a very long list of strings to >>>a Madhusudan> list of floats in a single statement ? >>> >>>Madhusudan> I have tried float(x) and float(x[:]) but neither work. I

Re: List of strings to list of floats ?

2005-10-17 Thread Steve Holden
Madhusudan Singh wrote: > [EMAIL PROTECTED] wrote: > > >>Madhusudan> Is it possible to convert a very long list of strings to a >>Madhusudan> list of floats in a single statement ? >> >>Madhusudan> I have tried float(x) and float(x[:]) but neither work. I >>Madhusudan> guess I wou

Re: List of strings to list of floats ?

2005-10-17 Thread Madhusudan Singh
[EMAIL PROTECTED] wrote: > > Madhusudan> Is it possible to convert a very long list of strings to a > Madhusudan> list of floats in a single statement ? > > Madhusudan> I have tried float(x) and float(x[:]) but neither work. I > Madhusudan> guess I would have to write a loop if t

Re: List of strings to list of floats ?

2005-10-15 Thread skip
Madhusudan> Is it possible to convert a very long list of strings to a Madhusudan> list of floats in a single statement ? Madhusudan> I have tried float(x) and float(x[:]) but neither work. I Madhusudan> guess I would have to write a loop if there isn't a way. Try: >>> los =

Re: List of strings

2005-08-18 Thread Tomi Kyöstilä
Paul Watson wrote: > Mohammed Altaj wrote: > >> Hi All >> >> Thanks for your reply , what i am doing is , i am reading from file , >> using readlines() , I would like to check in these lines , if there is >> line belong to another one or not , if it is , then i would like to >> delete it >> >> ['0

Re: List of strings

2005-08-17 Thread Paul Watson
Mohammed Altaj wrote: > Hi All > > Thanks for your reply , what i am doing is , i am reading from file , > using readlines() , I would like to check in these lines , if there is > line belong to another one or not , if it is , then i would like to > delete it > > ['0132442\n', '13\n', '24\n'] >