Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Stephen Hansen Newsgroups: comp.lang.python Subject: Re: Best way to clean up list items? Date: Mon, 02 May 2016 10:25:30 -0700 Lines: 15 Message-ID: References: <1462209930.1313497.595817481.73635112@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de YruoYZOiBkl98oZEzdk0hggxGCJvvFXg90rViuRGUw3g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:internal': 0.09; "','": 0.16; 'dfs': 0.16; 'list1': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:10.202.2.44': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:compute4.internal': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'have:': 0.18; 'stephen': 0.22; 'am,': 0.23; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'subject:list': 0.26; "i'm": 0.30; 'problem': 0.33; 'curious': 0.33; 'point,': 0.33; 'item': 0.35; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'received:66': 0.38; 'to:addr:python.org': 0.40; 'header:Message- Id:1': 0.61; 'generated.': 0.66; 'said:': 0.66; 'want:': 0.84; 'subject:Best': 0.93 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=ixokai.io; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=NF3lw5YlOh9PjO8JQGOHU37u+8A=; b=q4yeHE JqirtNkpqEbHf9+w/zJhelcFLYvVG+CK62LCrO3Dnvdn2xtATWV+EDDyTyWYQ5L5 6H09oO2mxoyDuKHDaORVgvcFwclTcOJ19MIAZC6Sf2gOLNtsplc4ZZUHOSDNupXI McY4vc2jPLECC+4tBvAvRqmpaisrCSmnPtRpw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=NF3lw5YlOh9PjO8 JQGOHU37u+8A=; b=S+VU9MTWmHzd3hyJ9krVYvFbgI41rXSed5PxbUQOk2QByGh 78Fw72CLUGQsJP7hd08iHs4190pBlhXRjl7MaxfKjy6y7o27R7TL21I9IKZBtMiD UJM3Nssmu5PZlj7juLcLHSbqlL6xnClupSFRmXJpkMw3VyLJh0oIuXBwPl1k= X-Sasl-Enc: UrJxcP5QTM19OjqjKYuOUAXDPp7xrOzbMVGyv4i6lIIz 1462209930 X-Mailer: MessagingEngine.com Webmail Interface - ajax-491eb5a4 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <1462209930.1313497.595817481.73635112@webmail.messagingengine.com> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:108022 On Mon, May 2, 2016, at 09:33 AM, DFS wrote: > Have: list1 = ['\r\n Item 1 ',' Item 2 ','\r\n '] I'm curious how you got to this point, it seems like you can solve the problem in how this is generated. > Want: list1 = ['Item 1','Item 2'] That said: list1 = [t.strip() for t in list1 if t and not t.isspace()] -- Stephen Hansen m e @ i x o k a i . i o