Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'removes': 0.05; 'space.': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:()': 0.09; '"write': 0.16; "'is',": 0.16; 'argument.': 0.16; 'message- id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sunny': 0.16; 'string': 0.17; 'element': 0.17; 'string,': 0.17; '>>>': 0.18; 'header:User- Agent:1': 0.26; 'guess': 0.27; 'raw': 0.27; 'header:X-Complaints- To:1': 0.28; 'received:132': 0.29; 'separated': 0.29; 'whitespace': 0.29; 'writes:': 0.29; 'words': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'code': 0.31; 'to:addr:python-list': 0.33; 'thanks': 0.34; 'list': 0.35; 'doing': 0.35; 'received:org': 0.36; 'but': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'best,': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'space': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'end': 0.40; 'between': 0.63; 'today': 0.67; 'weather': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Wolfgang Maier Subject: Re: join() Date: Wed, 20 Mar 2013 14:34:55 +0000 (UTC) References: <6110d82b-fce9-4146-8fcc-3276334a8f5f@14g2000vbr.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: sea.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 132.230.1.31 (Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363790118 news.xs4all.nl 6864 [2001:888:2000:d::a6]:59626 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41598 franzferdinand hotmail.com> writes: > > I'm doing this "Write code that removes whitespace at the beginning > and end of a string, and normalizes whitespace between words to be a > single space character" > > I can do it using split() > > >>> raw = " the weather is sunny today " > >>> raw.split() > ['the', 'weather', 'is', 'sunny', 'today'] > > But how do I do it using join() ?? Thanks > I guess you mean: how can I re-generate a string from my list of sub-strings, where each element is separated by only a single space. ' '.join(raw.split()) join is a string method that can take a list of strings to join as its argument. Best, Wolfgang