Diez B. Roggisch wrote:
Pat wrote:
I have written chunks of Python code that look this:
new_array = []
for a in array:
if not len( a ):
continue
new_array.append( a )
new_array = [a for a in array if len(a)]
and...
string = ""
for r in r
Steven D'Aprano wrote:
On Mon, 20 Oct 2008 10:20:03 -0400, Pat wrote:
Finally, if someone could point me to a good tutorial or explain list
compressions I would be forever in your debt.
Think of a for-loop:
for x in (1, 2, 3):
x
Creates x=1, then x=2, then x=3. It doesn't do anything wi
Pat a écrit :
I have written chunks of Python code that look this:
new_array = []
for a in array:
if not len( a ):
continue
new_array.append( a )
# à la lisp
new_array = filter(None, array)
# à la haskell
new_array = [a for a in array if a]
NB : all built
On Mon, 20 Oct 2008 10:20:03 -0400, Pat wrote:
> Finally, if someone could point me to a good tutorial or explain list
> compressions I would be forever in your debt.
Think of a for-loop:
for x in (1, 2, 3):
x
Creates x=1, then x=2, then x=3. It doesn't do anything with the x's, but
just c
Pat wrote:
> I have written chunks of Python code that look this:
>
> new_array = []
> for a in array:
> if not len( a ):
> continue
> new_array.append( a )
new_array = [a for a in array if len(a)]
> and...
>
> string = ""
> for r in results:
I have written chunks of Python code that look this:
new_array = []
for a in array:
if not len( a ):
continue
new_array.append( a )
and...
string = ""
for r in results:
if not r.startswith( '#' ):
string =+ r
It seems that a list