Re: converting boolean filter function to lambda

2015-06-25 Thread Mark Lawrence
On 26/06/2015 01:57, Ethan Furman wrote: On 06/25/2015 05:09 PM, Mark Lawrence wrote: On 26/06/2015 00:59, Chris Angelico wrote: On Fri, Jun 26, 2015 at 1:59 AM, Ethan Furman wrote: My attempt at a lambda function fails: filter(lambda p: (p in c for c in contacts), main) # ['291.792.9001', '

Re: converting boolean filter function to lambda

2015-06-25 Thread Ethan Furman
On 06/25/2015 05:09 PM, Mark Lawrence wrote: On 26/06/2015 00:59, Chris Angelico wrote: On Fri, Jun 26, 2015 at 1:59 AM, Ethan Furman wrote: My attempt at a lambda function fails: filter(lambda p: (p in c for c in contacts), main) # ['291.792.9001', '291.792.9000'] Besides using a lambda ;)

Re: converting boolean filter function to lambda

2015-06-25 Thread Mark Lawrence
On 26/06/2015 00:59, Chris Angelico wrote: On Fri, Jun 26, 2015 at 1:59 AM, Ethan Furman wrote: My attempt at a lambda function fails: filter(lambda p: (p in c for c in contacts), main) # ['291.792.9001', '291.792.9000'] Besides using a lambda ;) , what have I done wrong? This looks like a

Re: converting boolean filter function to lambda

2015-06-25 Thread Chris Angelico
On Fri, Jun 26, 2015 at 1:59 AM, Ethan Furman wrote: > My attempt at a lambda function fails: > > filter(lambda p: (p in c for c in contacts), main) > # ['291.792.9001', '291.792.9000'] > > Besides using a lambda ;) , what have I done wrong? This looks like a job for a list comprehension! (Cue t

Re: converting boolean filter function to lambda

2015-06-25 Thread Peter Otten
Ethan Furman wrote: > I have the following function: > > def phone_found(p): >for c in contacts: > if p in c: >return True >return False > > with the following test data: > > contacts = ['672.891.7280 x999', '291.792.9000 x111'] > main = ['291.792.9001', '291.792.9000'] >

Re: converting boolean filter function to lambda

2015-06-25 Thread Ian Kelly
On Thu, Jun 25, 2015 at 9:59 AM, Ethan Furman wrote: > I have the following function: > > def phone_found(p): > for c in contacts: > if p in c: > return True > return False > > with the following test data: > > contacts = ['672.891.7280 x999', '291.792.9000 x111'] > main = ['291.792.

converting boolean filter function to lambda

2015-06-25 Thread Ethan Furman
I have the following function: def phone_found(p): for c in contacts: if p in c: return True return False with the following test data: contacts = ['672.891.7280 x999', '291.792.9000 x111'] main = ['291.792.9001', '291.792.9000'] which works: filter(phone_found, main) # ['291.79