From: Adam B. <ada...@gb...> - 2001-02-23 05:26:23
|
The JPython mailing list is technically retired now, I've copied jython-users. sort() changes the state of the list so that it's sorted. >>> x = [ 'e', 'a', 'y', 'k', 'l' ] >>> print x ['e', 'a', 'y', 'k', 'l'] >>> x.sort() >>> print x ['a', 'e', 'k', 'l', 'y'] If you want to keep the unsorted data you need to take a copy, ie, y = x. Adam Burke www.gbst.com > -----Original Message----- > From: Steve Yegge [SMTP:st...@ca...] > Sent: Friday, February 23, 2001 3:19 PM > To: jpy...@py... > Subject: [JPython] problem with sort() > > rI've got a dictionary whose keys I want to print in sorted order. > If I call mydict.keys().sort(), the result is None: > > keys = self.spells.keys() > print "keys: ", keys > sorted = keys.sort() > print sorted > > results in: > > keys: ['curse spell', 'lightning bolt spell', ...] > None > > Do I have to make a copy of the keys list in order to sort it? > The python docs seem to suggest I can just slap a call to sort() > on the key set to iterate over it in sorted order. > > -steve > > > _______________________________________________ > JPython-Interest maillist - JPy...@py... > http://mail.python.org/mailman/listinfo/jpython-interest |