.split() Qeustion
Alister
alister.ware at ntlworld.com
Wed Aug 14 04:30:17 EDT 2013
On Tue, 13 Aug 2013 22:12:56 -0700, Gary Herron wrote:
> On 08/13/2013 09:51 PM, eschneider92 at 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
--
Accuracy, n.:
The vice of being right
More information about the Python-list
mailing list