Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'definitions': 0.07; 'referring': 0.07; 'latter': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'type,': 0.09; 'random': 0.14; '"""\\': 0.16; '"d"': 0.16; '(am': 0.16; 'cherry': 0.16; 'code?': 0.16; 'comma': 0.16; 'email addr:comcast.net': 0.16; 'readable': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'statement.': 0.16; 'wrote:': 0.18; 'typing': 0.19; 'meant': 0.20; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'header:User- Agent:1': 0.23; 'this:': 0.26; 'skip:" 20': 0.27; 'header:X -Complaints-To:1': 0.27; 'correct': 0.29; 'words': 0.29; 'easier': 0.31; 'lines': 0.31; '-0700,': 0.31; '>>>>': 0.31; 'gary': 0.31; 'strip': 0.31; 'lists': 0.32; 'reader': 0.33; 'agree': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'method': 0.36; 'example,': 0.37; 'list': 0.37; 'thank': 0.38; 'problems': 0.38; 'apple': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'how': 0.40; 'august': 0.61; 'first': 0.61; 'you.': 0.62; 'save': 0.62; 'more': 0.64; 'taking': 0.65; 'between': 0.67; 'characters,': 0.84; 'clearer': 0.84; 'pie': 0.84; 'developments': 0.95; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: .split() Qeustion Date: Wed, 14 Aug 2013 13:45:19 +0200 Organization: None References: <94f8428f-50b9-4ccd-95a0-6eeafda0fe18@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p50848489.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 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: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376480697 news.xs4all.nl 15969 [2001:888:2000:d::a6]:50603 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52507 Joshua Landau wrote: > 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", ... > "same problems the latter was designed to solve." > ] > > really more readable than: > > lines = """\ > Developments in high-speed rail, and high-speed ... > same problems the latter was designed to solve. > """[1:-1].split("\n") > > ? It's definitely more correct -- unless you meant to strip the "D" from the first line ;) I would use lines = """\ Developments in high-speed rail, and high-speed ... same problems the latter was designed to solve. """.splitlines()