On 27/04/2012 5:57 a.m., Kiuhnm wrote:
On 4/26/2012 19:48, Paul Rubin wrote:
Roy Smithr...@panix.com writes:
x = [a for a in iterable while a]
from itertools import takewhile
x = takewhile(bool, a)
I see that as a 'temporary' solution, otherwise we wouldn't need 'if'
inside of list
On Fri, Apr 27, 2012 at 7:49 PM, Miles Rout miles.r...@gmail.com wrote:
We have if inside list comprehensions? I didn't know that, could you provide
an example?
You mean like:
[x*2+1 for x in range(10) if x%3]
?
ChrisA
--
http://mail.python.org/mailman/listinfo/python-list
On 4/27/2012 11:49, Miles Rout wrote:
On 27/04/2012 5:57 a.m., Kiuhnm wrote:
On 4/26/2012 19:48, Paul Rubin wrote:
Roy Smithr...@panix.com writes:
x = [a for a in iterable while a]
from itertools import takewhile
x = takewhile(bool, a)
I see that as a 'temporary' solution, otherwise we
On Fri, 2012-04-27 at 19:57 +1000, Chris Angelico wrote:
On Fri, Apr 27, 2012 at 7:49 PM, Miles Rout miles.r...@gmail.com wrote:
We have if inside list comprehensions? I didn't know that, could you provide
an example?
You mean like:
[x*2+1 for x in range(10) if x%3]
Or like:
print [
On Fri, Apr 27, 2012 at 8:37 PM, Tim Wintle tim.win...@teamrubber.com wrote:
Or like:
print [ 0 if b%2==1 else 1 for b in range(10)]
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0]
That's nothing to do with the list comp, that's just the expression-if
syntax that you can use anywhere.
ChrisA
--
On Fri, 27 Apr 2012 19:57:31 +1000
Chris Angelico ros...@gmail.com wrote:
On Fri, Apr 27, 2012 at 7:49 PM, Miles Rout miles.r...@gmail.com wrote:
We have if inside list comprehensions? I didn't know that, could you provide
an example?
You mean like:
[x*2+1 for x in range(10) if x%3]
On Fri, Apr 27, 2012 at 10:17 PM, John O'Hagan resea...@johnohagan.com wrote:
results = [x = expensive_call(i) for i in iterable if condition(x)]
Nest it:
results = [x for x in (expensive_call(i) for i in iterable) if condition(x)]
ChrisA
--
http://mail.python.org/mailman/listinfo/python-list
On 04/27/12 07:23, Chris Angelico wrote:
On Fri, Apr 27, 2012 at 10:17 PM, John O'Haganresea...@johnohagan.com wrote:
results = [x = expensive_call(i) for i in iterable if condition(x)]
Nest it:
results = [x for x in (expensive_call(i) for i in iterable) if condition(x)]
While it's what I
I'm not seriously suggesting this as a language addition, just an interesting
idea to simplify some code I'm writing now:
x = [a for a in iterable while a]
which equates to:
x = []
for a in iterable:
if not a:
break
x.append(a)
It does has a few things going for it. It
On Thu, Apr 26, 2012 at 10:02 AM, Roy Smith r...@panix.com wrote:
I'm not seriously suggesting this as a language addition, just an interesting
idea to simplify some code I'm writing now:
x = [a for a in iterable while a]
which equates to:
x = []
for a in iterable:
if not a:
On Thu, Apr 26, 2012 at 10:02 AM, Roy Smith r...@panix.com wrote:
I'm not seriously suggesting this as a language addition, just an interesting
idea to simplify some code I'm writing now:
x = [a for a in iterable while a]
which equates to:
x = []
for a in iterable:
if not a:
On Thu, Apr 26, 2012 at 11:02 AM, Roy Smith r...@panix.com wrote:
I'm not seriously suggesting this as a language addition, just an interesting
idea to simplify some code I'm writing now:
x = [a for a in iterable while a]
which equates to:
x = []
for a in iterable:
if not a:
On 26/04/2012 18:02, Roy Smith wrote:
I'm not seriously suggesting this as a language addition, just an interesting
idea to simplify some code I'm writing now:
x = [a for a in iterable while a]
which equates to:
x = []
for a in iterable:
if not a:
break
x.append(a)
It
On 4/26/2012 19:02, Roy Smith wrote:
I'm not seriously suggesting this as a language addition, just an interesting
idea to simplify some code I'm writing now:
x = [a for a in iterable while a]
which equates to:
x = []
for a in iterable:
if not a:
break
x.append(a)
It does
Roy Smith r...@panix.com writes:
x = [a for a in iterable while a]
from itertools import takewhile
x = takewhile(bool, a)
--
http://mail.python.org/mailman/listinfo/python-list
On 4/26/2012 19:48, Paul Rubin wrote:
Roy Smithr...@panix.com writes:
x = [a for a in iterable while a]
from itertools import takewhile
x = takewhile(bool, a)
I see that as a 'temporary' solution, otherwise we wouldn't need 'if'
inside of list comprehensions either.
Kiuhnm
--
On Thu, Apr 26, 2012 at 11:57 AM, Kiuhnm
kiuhnm03.4t.yahoo...@mail.python.org wrote:
On 4/26/2012 19:48, Paul Rubin wrote:
Roy Smithr...@panix.com writes:
x = [a for a in iterable while a]
from itertools import takewhile
x = takewhile(bool, a)
I see that as a 'temporary' solution,
17 matches
Mail list logo