Path: csiph.com!aioe.org!news.stack.nl!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'suppose': 0.07; 'string': 0.09; 'predefined': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'random': 0.14; "'__doc__',": 0.16; "'r',": 0.16; '(am': 0.16; 'apostrophes': 0.16; 'cherry': 0.16; 'code?': 0.16; 'comma': 0.16; 'skip:> 20': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'typing': 0.19; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; '>>>': 0.24; 'string,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'words': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; "skip:' 10": 0.31; '13,': 0.31; 'gary': 0.31; 'file': 0.32; 'url:python': 0.33; 'objects': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'skip:> 10': 0.36; 'var': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'list': 0.37; 'list.': 0.37; 'thank': 0.38; 'apple': 0.38; 'same.': 0.38; 'pm,': 0.38; 'ability': 0.39; 'skip:& 20': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'how': 0.40; 'hope': 0.61; 'you.': 0.62; 'talking': 0.65; 'between': 0.67; 'clarifies': 0.84; 'pie': 0.84; 'to:addr:comcast.net': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=NKUaG+vdu5h7N3r9zEonvkULUIixqES+0epO0fVH/MA=; b=PtYKTloH8siK5g1AS2crACs9nGfFHwpNF+DiTIaRe9H1Mc4DXFs/emz/rMPQPzgopB 1IUFKbZUEraDdrRsmp8gyU1KzwevHaWFWHdAImrktJuYtYYxxZ0sEoQ7B5WIUXTAcm/e Wk6hTrp81IruJb3jUxYm4jnj/J5cFVXx2NxuI7xIaLp3bvtWdfgXCAYBNRJCJ6jwH2O5 3QfUc2zHznVhlzbxkLDFPOEkewBNoeBz6dff8tjQmTILOuSou3Nbvxz6mVwKRJlYGK/m U/u5ssWi2mbkzXenrv4z2q4V5w8zPcmZh/X6cKIBuK+YGubKQm7OA9Y512jZVv8do1CG qr6A== MIME-Version: 1.0 X-Received: by 10.180.100.225 with SMTP id fb1mr950031wib.22.1376458671943; Tue, 13 Aug 2013 22:37:51 -0700 (PDT) In-Reply-To: <94f8428f-50b9-4ccd-95a0-6eeafda0fe18@googlegroups.com> References: <94f8428f-50b9-4ccd-95a0-6eeafda0fe18@googlegroups.com> Date: Tue, 13 Aug 2013 22:37:51 -0700 Subject: Re: .split() Qeustion From: Krishnan Shankar To: kurt schwitters Content-Type: multipart/alternative; boundary=f46d0444e97930761804e3e1c2ef X-Mailman-Approved-At: Wed, 14 Aug 2013 07:43:29 +0200 Cc: python-list@python.org 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: 151 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376459009 news.xs4all.nl 15924 [2001:888:2000:d::a6]:60648 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52495 --f46d0444e97930761804e3e1c2ef Content-Type: text/plain; charset=ISO-8859-1 Hi, >How can I use the '.split()' method (am I right in calling it a method?) The .split() is a method in Python which comes as in built method for String objects in Python. Any string defined in python will have the ability to call this function. >>> var = 'Hello how r u?' >>> dir(var) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] >>> var.split() ['Hello', 'how', 'r', 'u?'] >>> >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)) If you are talking about having predefined list pie with limited elements like above it is ok to code them straightaway with apostrophes and others will know that it is a predefined list. Suppose if the elements in list come as a line in a file or is a string, it will be better to use split() method and form a list. I hope Gary has provided the example for the same. pie = 'keylime peach apple cherry pecan'.split() I hope this clarifies your doubt. Regards, Krishnan On Tue, Aug 13, 2013 at 9:51 PM, 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 > -- > http://mail.python.org/mailman/listinfo/python-list > --f46d0444e97930761804e3e1c2ef Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,

>How can I use the '.split()' method (a= m I right in calling it a method?)

The .split() is a method in Python which comes as in buil= t method for String objects in Python. Any string defined in python will ha= ve the ability to call this function.

>>= ;> var =3D 'Hello how r u?'
>>> dir(var)
['__add__', '__class__'= ;, '__contains__', '__delattr__', '__doc__', '_= _eq__', '__ge__', '__getattribute__', '__getitem__&= #39;, '__getnewargs__', '__getslice__', '__gt__', &= #39;__hash__', '__init__', '__le__', '__len__',= '__lt__', '__mod__', '__mul__', '__ne__', = '__new__', '__reduce__', '__reduce_ex__', '__re= pr__', '__rmod__', '__rmul__', '__setattr__', &= #39;__str__', 'capitalize', 'center', 'count', = 'decode', 'encode', 'endswith', 'expandtabs'= ;, 'find', 'index', 'isalnum', 'isalpha', &= #39;isdigit', 'islower', 'isspace', 'istitle', = 'isupper', 'join', 'ljust', 'lower', 'l= strip', 'replace', 'rfind', 'rindex', 'rjus= t', 'rsplit', 'rstrip', 'split', 'splitline= s', 'startswith', 'strip', 'swapcase', 'tit= le', 'translate', 'upper', 'zfill']
>>> var.split()
['Hello', 'how', &#= 39;r', 'u?']
>>>

<= div>>writing= each comma between words in the pie list in the following code? Also, is t= here >a way to use .split instead of typing the apostrophes? Thank you.<= /span>

>import random
>pie=3D['keylime', 'peach= ', 'apple', 'cherry', 'pecan']
>print(rando= m.choice(pie))

If you are talking about having predefined li= st pie with limited elements like above it is ok to code them straightaway = with apostrophes and others will know that it is a predefined list.

Suppose if the elements in list come as a line in a fil= e or is a string, it will be better to use split() method and form a list. = I hope Gary has provided the example for the same.

pie =3D 'keylime peach apple cherry pecan'.split()

I hope thi= s clarifies your doubt.

Regards,
Krishnan



On Tue, Aug 13, 2013 at 9: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 t= o use .split instead of typing the apostrophes? Thank you.

import random
pie=3D['keylime', 'peach', 'apple', 'cherry'= ;, 'pecan']
print(random.choice(pie))

Eric
--
http://mail.python.org/mailman/listinfo/python-list

--f46d0444e97930761804e3e1c2ef--