Re: Half-baked idea: list comprehensions with while

2012-04-27 Thread Miles Rout
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

Re: Half-baked idea: list comprehensions with while

2012-04-27 Thread Chris Angelico
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

Re: Half-baked idea: list comprehensions with while

2012-04-27 Thread Kiuhnm
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

Re: Half-baked idea: list comprehensions with while

2012-04-27 Thread Tim Wintle
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 [

Re: Half-baked idea: list comprehensions with while

2012-04-27 Thread Chris Angelico
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 --

Re: Half-baked idea: list comprehensions with while

2012-04-27 Thread John O'Hagan
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]

Re: Half-baked idea: list comprehensions with while

2012-04-27 Thread Chris Angelico
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

Re: Half-baked idea: list comprehensions with while

2012-04-27 Thread Tim Chase
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

Half-baked idea: list comprehensions with while

2012-04-26 Thread Roy Smith
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

Re: Half-baked idea: list comprehensions with while

2012-04-26 Thread Chris Rebert
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:        

Re: Half-baked idea: list comprehensions with while

2012-04-26 Thread Chris Kaynor
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:        

Re: Half-baked idea: list comprehensions with while

2012-04-26 Thread Ian Kelly
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:        

Re: Half-baked idea: list comprehensions with while

2012-04-26 Thread Mark Lawrence
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

Re: Half-baked idea: list comprehensions with while

2012-04-26 Thread Kiuhnm
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

Re: Half-baked idea: list comprehensions with while

2012-04-26 Thread Paul Rubin
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

Re: Half-baked idea: list comprehensions with while

2012-04-26 Thread Kiuhnm
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 --

Re: Half-baked idea: list comprehensions with while

2012-04-26 Thread Ian Kelly
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,