Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30438
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-09-28 17:24 -0700 |
| References | <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> <mailman.1587.1348875975.27098.python-list@python.org> <b3564f31-f54c-4c00-a6e7-f497911c054a@googlegroups.com> |
| Subject | Re: creating an artificial "last element" in sort list |
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
| Message-ID | <mailman.1590.1348878303.27098.python-list@python.org> (permalink) |
dave於 2012年9月29日星期六UTC+8上午7時51分10秒寫道: > more clearer, this is a more realistic use case: > > > > ['awefawef', 'awefawfsf', 'awefsdf', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz'] > > > > and the quantity of ''zzzzzzzzzzzzzz'' would be dynamic. > > > > On Friday, September 28, 2012 4:46:15 PM UTC-7, Ian wrote: > > > > > > > > > a = ['a', 'b', x] > > > > > > > > > > > > > > b = sorted(a) > > > > > > > > > > > > > > What does x need to be to always be last on an ascending sort no matter what 'a' and 'b' are.... within reason... I am expecting 'a' and 'b' will be not longer than 10 char's long.... I tried making x = 'zzzzzzzzzzzzzzzz' and believe it or not, this appears FIRST on the sort!!! > > > > > > > > > > > > It appears last when I run the code. > > > > > > > > > > > > To answer your question, though, if you want to force x to be last, > > > > > > then I suggest removing it from the list and then appending it to the > > > > > > end. I am thinking if it is helpful to preprocess an arbitrary list first into some set of unique ordered elements before a sort. Anyway lists are passed by references to functions in python.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
creating an artificial "last element" in sort list dave <davidreynon@gmail.com> - 2012-09-28 16:39 -0700
Re: creating an artificial "last element" in sort list Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-28 17:45 -0600
Re: creating an artificial "last element" in sort list dave <davidreynon@gmail.com> - 2012-09-28 16:51 -0700
Re: creating an artificial "last element" in sort list 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-28 17:24 -0700
Re: creating an artificial "last element" in sort list 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-28 17:24 -0700
Re: creating an artificial "last element" in sort list Demian Brecht <demianbrecht@gmail.com> - 2012-09-28 17:32 -0700
Re: creating an artificial "last element" in sort list Demian Brecht <demianbrecht@gmail.com> - 2012-09-28 17:59 -0700
Re: creating an artificial "last element" in sort list Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-28 21:29 -0600
Re: creating an artificial "last element" in sort list Demian Brecht <demianbrecht@gmail.com> - 2012-09-28 17:59 -0700
Re: creating an artificial "last element" in sort list duncan smith <buzzard@invalid.invalid> - 2012-09-29 02:19 +0100
Re: creating an artificial "last element" in sort list dave <davidreynon@gmail.com> - 2012-09-28 16:51 -0700
Re: creating an artificial "last element" in sort list Paul Rubin <no.email@nospam.invalid> - 2012-09-28 18:42 -0700
Re: creating an artificial "last element" in sort list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-29 02:05 +0000
csiph-web