Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Peter Pearson Newsgroups: comp.lang.python Subject: Re: filter a list of strings Date: 5 Dec 2015 19:42:04 GMT Lines: 16 Message-ID: References: X-Trace: individual.net 0kFWoo3hk4dIvdXpXLpfGQVsfj7ZBhNmpz/6zEnSakHoU1mBK3 Cancel-Lock: sha1:4d3XxvLbYcluG689xYbHfPSfU7Y= User-Agent: slrn/pre1.0.0-18 (Linux) Xref: csiph.com comp.lang.python:100044 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 up! List comprehensions are one of the coolest things in Python. Maybe this simple example will make it click for you: >>> [x**2 for x in [1,2,3,4] if x != 2] [1, 9, 16] -- To email me, substitute nowhere->runbox, invalid->com.