Re: Sorting a list depending of the indexes of another sorted list
- From: Steven D'Aprano <steve@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 21 Jan 2008 12:52:23 -0000
On Mon, 21 Jan 2008 17:32:42 +0800, J. Peng wrote:
Steven D'Aprano 写道:
On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote:Thanks.
J. Peng 写道:
k = (i.split())[3]btw, why can't I write the above two into one statement?
y = (i.split())[1]
(k,y) = (i.split())[3,1]
I don't know. What's "i"?
I'm guessing "i" is a string (and what a horrible choice of a name for
a string!) So i.split() will return a list. List indexing with multiple
arguments isn't defined, which is why you can't write
k, y = (i.split())[3,1]
Then one have to split the list twice.Given the list is large,it's maybe
not good for performance.Is it a more effective split way?
Yes, split the string once and store it.
words = "Nobody expects the Spanish Inquisition!"
alist = words.split()
k = alist[3] # "Spanish"
y = alist[1] # "expects"
--
Steven
.
- References:
- Sorting a list depending of the indexes of another sorted list
- From: Santiago Romero
- Re: Sorting a list depending of the indexes of another sorted list
- From: J. Peng
- Re: Sorting a list depending of the indexes of another sorted list
- From: Steven D'Aprano
- Re: Sorting a list depending of the indexes of another sorted list
- From: J. Peng
- Sorting a list depending of the indexes of another sorted list
- Prev by Date: Re: Basic inheritance question
- Next by Date: Re: Q: paramiko/SSH/ how to get a remote host_key
- Previous by thread: Re: Sorting a list depending of the indexes of another sorted list
- Next by thread: Re: Sorting a list depending of the indexes of another sorted list
- Index(es):
Relevant Pages
|