Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'definitions': 0.07; 'modified': 0.07; 'referring': 0.07; 'forms,': 0.09; 'historically': 0.09; 'hour.': 0.09; 'latter': 0.09; 'obstacles': 0.09; 'type,': 0.09; 'cc:addr:python-list': 0.11; 'random': 0.14; '"""\\': 0.16; '"by': 0.16; '(am': 0.16; 'a",': 0.16; 'cherry': 0.16; 'code?': 0.16; 'comma': 0.16; 'email addr:comcast.net': 0.16; 'precedence': 0.16; 'readable': 0.16; 'statement.': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'typing': 0.19; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'finally,': 0.24; 'cc:2**0': 0.24; 'extension': 0.26; 'this:': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'words': 0.29; 'message-id:@mail.gmail.com': 0.30; 'easier': 0.31; 'lines': 0.31; '-0700,': 0.31; 'gary': 0.31; 'trivial': 0.31; 'lists': 0.32; 'maintaining': 0.32; 'reader': 0.33; '"the': 0.34; 'agree': 0.35; 'convert': 0.35; 'editor': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'shorter': 0.36; 'method': 0.36; 'should': 0.36; 'example,': 0.37; 'list': 0.37; 'being': 0.38; 'system,': 0.38; 'thank': 0.38; 'problems': 0.38; 'apple': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'august': 0.61; 'simple': 0.61; 'you.': 0.62; 'save': 0.62; 'complete': 0.62; 'high': 0.63; 'kind': 0.63; 'such': 0.63; 'become': 0.64; 'more': 0.64; 'taking': 0.65; 'kept': 0.65; 'air': 0.66; 'managing': 0.66; 'between': 0.67; 'difficulty': 0.68; 'employing': 0.68; 'viewed': 0.74; 'characters,': 0.84; 'clearer': 0.84; 'pie': 0.84; 'to:addr:ntlworld.com': 0.84; 'eliminates': 0.91; 'developments': 0.95; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=3ZBN8WA4S786pxKvx2qA784yxE8v1L5dO6BO9IU85nA=; b=KGYcw6cptBoCqCeyz91ilAd/n2oY3txbzFRNcBS0qK4jQF6bNxrPF0Id/iQQNRLtV8 0l2X1f6Q+NI+NJIuK1ZsDo1qGO3BN+MXtj6wZfHRIMr1+1iO/n2xltM8djjYmHTYE/// MrP/O0a4EG+usDIMxFglj0vCT7gDMa5UutyAtVeCwuJgrKL9rgWz2HwZjL6fi87zgSRR eLCbd6NYlp40hZkZv8ewo8d1vgvH1dACb9t9Itr39GWxuv08wuQgtVIFly2hb19CSMRi VWDk19NdMdLza6Y/5Oyl9lmMftWuUMATNBYe483jb55rs+iuJztJzKPdFnUM+zvfgUAk +u2A== X-Received: by 10.112.22.102 with SMTP id c6mr7493310lbf.1.1376476301852; Wed, 14 Aug 2013 03:31:41 -0700 (PDT) MIME-Version: 1.0 Sender: joshua.landau.ws@gmail.com In-Reply-To: References: <94f8428f-50b9-4ccd-95a0-6eeafda0fe18@googlegroups.com> From: Joshua Landau Date: Wed, 14 Aug 2013 11:31:01 +0100 X-Google-Sender-Auth: uARu_ZBJ9UxBzMMUqHekCVBGIyg Subject: Re: .split() Qeustion To: Alister Content-Type: text/plain; charset=UTF-8 Cc: python-list 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: 75 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376476309 news.xs4all.nl 15968 [2001:888:2000:d::a6]:41365 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52505 On 14 August 2013 09:30, Alister wrote: > On Tue, 13 Aug 2013 22:12:56 -0700, Gary Herron wrote: > >> On 08/13/2013 09:51 PM, eschneider92@comcast.net wrote: >>> How can I use the '.split()' method (am I right in calling it a >>> method?) without instead of writing each comma between words in the pie >>> list in the following code? Also, is there a way to use .split instead >>> of typing the apostrophes? Thank you. >>> >>> import random pie=['keylime', 'peach', 'apple', 'cherry', 'pecan'] >>> print(random.choice(pie)) >>> >>> Eric >> >> I think you are referring to this: >> pie = 'keylime peach apple cherry pecan'.split() >> >> While it's easier to type, and does save a few characters, I think the >> original list is clearer to a reader of your program. >> >> Gary Herron > > I would agree with the last statement. > Please write list definitions as lists rather than taking a short-cut to > save a few key presses That's true with this example, but is: lines = [ "Developments in high-speed rail, and high-speed", "transport more generally, have historically been", "impeded by the difficulties in managing friction", "and air resistance, both of which become", "substantial when vehicles approach high speeds.", "The vactrain concept eliminates these obstacles", "by employing magnetically levitating trains in", "tubes kept at a complete vacuum, allowing for", "heoretical speeds of thousands of miles per", "hour. The high cost of constructing such a system,", "however, and the difficulty of maintaining a", "vacuum over large distances, has prevented this", "type of system from ever being built. The", "Hyperloop can be viewed as a modified vactrain,", "employing more cost-effective solutions to the", "same problems the latter was designed to solve." ] really more readable than: lines = """\ Developments in high-speed rail, and high-speed transport more generally, have historically been impeded by the difficulties in managing friction and air resistance, both of which become substantial when vehicles approach high speeds. The vactrain concept eliminates these obstacles by employing magnetically levitating trains in tubes kept at a complete vacuum, allowing for heoretical speeds of thousands of miles per hour. The high cost of constructing such a system, however, and the difficulty of maintaining a vacuum over large distances, has prevented this type of system from ever being built. The Hyperloop can be viewed as a modified vactrain, employing more cost-effective solutions to the same problems the latter was designed to solve. """[1:-1].split("\n") ? Additionally,namedtuple has already set the precedence for this kind of thing. Finally, a simple extension or a decent editor should make it trivial to convert between the forms, so you can write the shorter way and convert on-the-fly.