discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] list comprehesnion in variable doesnt work


From: Eric Blossom
Subject: Re: [Discuss-gnuradio] list comprehesnion in variable doesnt work
Date: Sat, 30 May 2009 11:38:22 -0700
User-agent: Mutt/1.5.18 (2008-05-17)

On Sat, May 30, 2009 at 10:55:50AM +0000, feldmaus wrote:
> Hi All again,
> 
> list comprehension doesnt work in variables, for  example:
> [print(i) for i in range(3)]

"print" is a statement, not a function.  


I'd probably use:

  for i in range(3): print i


> or
> variable_2 = file('../../../tabs.dat','w')
> ([variable_2.write(str(i)) for i in [1,2]] is True) &\
>                   (variable_2.close() is True)
> doesnt work.

([v2.write(str(i)) for i in [1,2]] is True) and v2.close() is True


will of course always be False, since [None, None] is not True


It looks like you are trying to abuse list comprehensions for some kind
of control flow short cut.  I think of them as an equivalent to the
"map" builtin, a higher-order function.

You may want to consider "map" and "reduce" in combination.


Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]