Re: Sorting a list depending of the indexes of another sorted list



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:

J. Peng 写道:

k = (i.split())[3]
y = (i.split())[1]
btw, why can't I write the above two into one statement?

(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]


Thanks.
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
.



Relevant Pages

  • Re: A97 - what would you do 99 times out of a hundred?
    ... completely (not unusual, BTW). ... >owner table - dog found table has a 0 instead of any other number in the ... >me as no different as a zero length string. ...
    (comp.databases.ms-access)
  • Re: Syntax for multiple WHERE in recordset?
    ... > Heres what I have (and this work fine BTW): ... > cnn, adOpenDynamic, adLockReadOnly ... > I need another two criteria in the WHERE clause but this syntax is ... public function SQ(byval TextIn As String) as String) ...
    (microsoft.public.vb.controls)
  • Re: Yahoo! and Login system
    ... >> BTW, I'm still scratching my head on it. ... >>they're also passing the challenge string to the server and they pass ... Where all citizens are politicians and all politicians ...
    (comp.lang.php)
  • A newbie question about grep & find
    ... I am a Linux newbie, ... subdirectories for all *.c files containing the string 'socket'. ... BTW: Is there a way to make grep work recursively at all? ...
    (comp.os.linux.misc)
  • Complicated delete query
    ... FROM Alphadex ... BTW, note that all fields allow zero length string, so I can not just check ...
    (microsoft.public.access.queries)