Re: filter a list of strings

2015-12-09 Thread Sivan Greenberg
That might also work: new_list = [i for i in the_list if i not in targets] # given you have no special requirements for the selection # out of 'targets' -Sivan On Wed, Dec 9, 2015 at 12:58 AM, Thomas 'PointedEars' Lahn < pointede...@web.de> wrote: > Mark Lawrence wrote: > > > On 03/12/2015

Shadowing built-ins [was Re: filter a list of strings]

2015-12-08 Thread Steven D'Aprano
On Wednesday 09 December 2015 09:58, Thomas 'PointedEars' Lahn wrote: > Mark Lawrence wrote: > >> On 03/12/2015 01:15, c.bu...@posteo.jp wrote: >>> I would like to know how this could be done more elegant/pythonic. >>> >>> I have a big list (over 10.000 items) with strings (each 100 to 300 >>>

Re: filter a list of strings

2015-12-08 Thread Thomas 'PointedEars' Lahn
Mark Lawrence wrote: > On 03/12/2015 01:15, c.bu...@posteo.jp wrote: >> I would like to know how this could be done more elegant/pythonic. >> >> I have a big list (over 10.000 items) with strings (each 100 to 300 >> chars long) and want to filter them. >> >> list = . >> […] > > targets =

Re: filter a list of strings

2015-12-05 Thread Peter Pearson
On Thu, 3 Dec 2015 10:27:19 +0100, wrote: [snip] > I often saw constructions like this > x for x in y if ... > But I don't understand that combination of the Python keywords (for, > in, if) I allready know. It is to complex to imagine what there really > happen. Don't give

Re: filter a list of strings

2015-12-03 Thread Chris Angelico
On Thu, Dec 3, 2015 at 8:27 PM, wrote: > Thank you for your suggestion. This will help a lot. > > On 2015-12-03 08:32 Jussi Piitulainen wrote: >> list = [ item for item in list >> if ( 'Banana' not in item and >> 'Car' not in item

Re: filter a list of strings

2015-12-03 Thread Grobu
On 03/12/15 02:15, c.bu...@posteo.jp wrote: I would like to know how this could be done more elegant/pythonic. I have a big list (over 10.000 items) with strings (each 100 to 300 chars long) and want to filter them. list = . for item in list[:]: if 'Banana' in item:

Re: filter a list of strings

2015-12-03 Thread Jussi Piitulainen
writes: > Thank you for your suggestion. This will help a lot. > > On 2015-12-03 08:32 Jussi Piitulainen wrote: >> list = [ item for item in list >> if ( 'Banana' not in item and >> 'Car' not in item ) ] > > I often saw constructions like this > x for

Re: filter a list of strings

2015-12-03 Thread Mark Lawrence
On 03/12/2015 01:15, c.bu...@posteo.jp wrote: I would like to know how this could be done more elegant/pythonic. I have a big list (over 10.000 items) with strings (each 100 to 300 chars long) and want to filter them. list = . for item in list[:]: if 'Banana' in item:

Re: filter a list of strings

2015-12-03 Thread Wolfgang Maier
On 03.12.2015 10:27, c.bu...@posteo.jp wrote: > > I often saw constructions like this >x for x in y if ... > But I don't understand that combination of the Python keywords (for, > in, if) I allready know. It is to complex to imagine what there really > happen. > > I understand this >for x

Re: filter a list of strings

2015-12-03 Thread Laura Creighton
In a message of Thu, 03 Dec 2015 10:27:19 +0100, c.bu...@posteo.jp writes: >Thank you for your suggestion. This will help a lot. > >On 2015-12-03 08:32 Jussi Piitulainen wrote: >> list = [ item for item in list >> if ( 'Banana' not in item and >>

Re: filter a list of strings

2015-12-03 Thread jmp
On 12/03/2015 10:27 AM, c.bu...@posteo.jp wrote: I often saw constructions like this x for x in y if ... But I don't understand that combination of the Python keywords (for, in, if) I allready know. It is to complex to imagine what there really happen. I understand this for x in y:

Re: filter a list of strings

2015-12-03 Thread c.buhtz
Thank you for your suggestion. This will help a lot. On 2015-12-03 08:32 Jussi Piitulainen wrote: > list = [ item for item in list > if ( 'Banana' not in item and > 'Car' not in item ) ] I often saw constructions like this x for x in y if ... But

Re: filter a list of strings

2015-12-03 Thread Peter Otten
Laura Creighton wrote: > In a message of Thu, 03 Dec 2015 10:27:19 +0100, c.bu...@posteo.jp writes: >>Thank you for your suggestion. This will help a lot. >> >>On 2015-12-03 08:32 Jussi Piitulainen wrote: >>> list = [ item for item in list >>> if ( 'Banana' not in

Re: filter a list of strings

2015-12-03 Thread Denis McMahon
On Thu, 03 Dec 2015 08:32:49 +0200, Jussi Piitulainen wrote: > def isbad(item): > return ( 'Banana' in item or > 'Car' in item ) > > def isgood(item) > return not isbad(item) badthings = [ 'Banana', 'Car', ] def isgood(item) for thing in badthings: if

Re: filter a list of strings

2015-12-03 Thread Jussi Piitulainen
Denis McMahon writes: > On Thu, 03 Dec 2015 08:32:49 +0200, Jussi Piitulainen wrote: > >> def isbad(item): >> return ( 'Banana' in item or >> 'Car' in item ) >> >> def isgood(item) >> return not isbad(item) > > badthings = [ 'Banana', 'Car', ] > > def isgood(item) >

Re: filter a list of strings

2015-12-03 Thread Terry Reedy
On 12/3/2015 7:28 AM, Mark Lawrence wrote: On 03/12/2015 01:15, c.bu...@posteo.jp wrote: I would like to know how this could be done more elegant/pythonic. I have a big list (over 10.000 items) with strings (each 100 to 300 chars long) and want to filter them. list = . for item in

Re: filter a list of strings

2015-12-02 Thread Jussi Piitulainen
writes: > I would like to know how this could be done more elegant/pythonic. > > I have a big list (over 10.000 items) with strings (each 100 to 300 > chars long) and want to filter them. > > list = . > > for item in list[:]: > if 'Banana' in item: >

filter a list of strings

2015-12-02 Thread c.buhtz
I would like to know how this could be done more elegant/pythonic. I have a big list (over 10.000 items) with strings (each 100 to 300 chars long) and want to filter them. list = . for item in list[:]: if 'Banana' in item: list.remove(item) if 'Car' in item: list.remove(item)