Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Wolfgang Maier Newsgroups: comp.lang.python Subject: Re: filter a list of strings Date: Thu, 3 Dec 2015 10:46:54 +0100 Lines: 29 Message-ID: References: <3pBBdn3nVcz5vP8@dovecot03.posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de kZ4RaTBb+gkZNkeIzMOOwg3xhvDdhpa1/HBiI7r743Pg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'that?': 0.05; 'squares': 0.07; 'happen.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'subject:list': 0.26; 'header:X -Complaints-To:1': 0.26; 'equivalent': 0.27; 'received:132': 0.29; 'combination': 0.33; 'case,': 0.34; 'know.': 0.34; 'quite': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:org': 0.37; 'list.': 0.37; 'seem': 0.37; 'front': 0.38; 'to:addr:python.org': 0.40; 'some': 0.40; 'leading': 0.61; 'store,': 0.66; 'obvious': 0.76; 'saw': 0.77; 'imagine': 0.96 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 132.230.194.131 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: <3pBBdn3nVcz5vP8@dovecot03.posteo.de> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99948 On 03.12.2015 10:27, c.buhtz@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: > if ... > > But what is about the 'x' in front of all that? > The leading x states which value you want to put in the new list. This may seem obvious in the simple case, but quite often its not the original x-ses found in y that you want to store, but some transformation of it, e.g.: [x**2 for x in y] is equivalent to: squares = [] for x in y: squares.append(x**2)