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 = ['Banana', 'Car'...] > for item in list[:]: > for target in targets: > if target in item: > list.remove(item) > >> btw: Is it correct to iterate over a copy (list[:]) of that string list >> and not the original one? > > Absolutely :)
However, “list” is a built-in class/constructor that would be overwritten this way. One should choose another identifier than “list” for one’s variables. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. -- https://mail.python.org/mailman/listinfo/python-list