String question

2008-06-23 Thread Andreu

I want to split a sentence and assign each word to a variable.
In Ruby I can do it as:

v1,v2,v3,v4,v5 = str1.split

Which will be the Python equivalent ? Thanks.

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


Re: String question

2008-06-23 Thread Andreu

Wow...about ten seconds to get a kind response 
Thanks Tim.

Andrew.

Tim Golden wrote:

Andreu wrote:

I want to split a sentence and assign each word to a variable.
In Ruby I can do it as:

v1,v2,v3,v4,v5 = str1.split

Which will be the Python equivalent ? Thanks.


That would be:

str1 = "The quick brown fox jumps"
v1, v2, v3, v4, v5 = str1.split ()

TJG

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


Re: String question

2008-06-23 Thread Andreu

Yes, ... don't ask me why, but in fact  v1,v2,v3 = str1.split()
does not seem to work. My original problem was I forgot about
the parenthesis as Tim point out. So I ended up converting to a
list as in:  v = str1.split() and accessing the elements using
v[0] v[1] ect...it is working now. Thanks.

Andreu.


[EMAIL PROTECTED] wrote:

However I would make a list of it.

v_list = example.split()

That seems to me to be the more pythonic way to do it, since it is
dynamic.

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