On 04/27/12 07:23, Chris Angelico wrote:
On Fri, Apr 27, 2012 at 10:17 PM, John O'Hagan 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 do in cases like this,
On Fri, Apr 27, 2012 at 10:17 PM, John O'Hagan 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 Fri, 27 Apr 2012 19:57:31 +1000
Chris Angelico wrote:
> On Fri, Apr 27, 2012 at 7:49 PM, Miles Rout 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]
>
Speaking of list comprehen
On Fri, Apr 27, 2012 at 8:37 PM, Tim Wintle 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
--
http://mail.python.org/mailman/
On Fri, 2012-04-27 at 19:57 +1000, Chris Angelico wrote:
> On Fri, Apr 27, 2012 at 7:49 PM, Miles Rout 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 [ 0 if b%2=
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 Smith 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 'i
On Fri, Apr 27, 2012 at 7:49 PM, Miles Rout 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 27/04/2012 5:57 a.m., Kiuhnm wrote:
On 4/26/2012 19:48, Paul Rubin wrote:
Roy Smith 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
On Thu, Apr 26, 2012 at 11:57 AM, Kiuhnm
wrote:
> On 4/26/2012 19:48, Paul Rubin wrote:
>>
>> Roy Smith 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 'i
On 4/26/2012 19:48, Paul Rubin wrote:
Roy Smith 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
--
http://mail.python.org/m
Roy Smith 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: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
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 does
On Thu, Apr 26, 2012 at 11:02 AM, 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:
> brea
On Thu, Apr 26, 2012 at 10:02 AM, 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:
> br
On Thu, Apr 26, 2012 at 10:02 AM, 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:
> brea
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 doesn't
17 matches
Mail list logo