creating an artificial last element in sort list

2012-09-28 Thread dave
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 = '' and believe it or not, this appears

Re: creating an artificial last element in sort list

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 5:39 PM, dave davidrey...@gmail.com 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

Re: creating an artificial last element in sort list

2012-09-28 Thread dave
more clearer, this is a more realistic use case: ['awefawef', 'awefawfsf', 'awefsdf', 'zz', 'zz', 'zz'] and the quantity of ''zz'' would be dynamic. On Friday, September 28, 2012 4:46:15 PM UTC-7, Ian wrote: a = ['a', 'b', x] b =

Re: creating an artificial last element in sort list

2012-09-28 Thread Demian Brecht
Maybe l = filter(a, lambda v: v == a[-1]) sorted(a[:-len(l)]) + l ? On Fri, Sep 28, 2012 at 4:51 PM, dave davidrey...@gmail.com wrote: more clearer, this is a more realistic use case: ['awefawef', 'awefawfsf', 'awefsdf', 'zz', 'zz', 'zz'] and the

Re: creating an artificial last element in sort list

2012-09-28 Thread 88888 Dihedral
dave於 2012年9月29日星期六UTC+8上午7時51分10秒寫道: more clearer, this is a more realistic use case: ['awefawef', 'awefawfsf', 'awefsdf', 'zz', 'zz', 'zz'] and the quantity of ''zz'' would be dynamic. On Friday, September 28, 2012 4:46:15

Re: creating an artificial last element in sort list

2012-09-28 Thread Demian Brecht
Apparently gmail hates me and my last response didn't get through: a = ['awefawef', 'awefawfsf', 'awefsdf', 'zz', 'zz', 'zz'] f = filter(lambda s: s == a[-1], a) l = sorted(lst[:-len(f)]) + f Now, not 100% sure about efficiency over large sizes of a, but

Re: creating an artificial last element in sort list

2012-09-28 Thread Demian Brecht
f = filter(lambda s: s == a[-1], a) That line's assuming that the last element may also be found in arbitrary locations in the list. If it's guaranteed that they're all contiguous at the upper bounds, I'd just walk the list backwards until I found one that wasn't matching rather than

Re: creating an artificial last element in sort list

2012-09-28 Thread duncan smith
On 29/09/12 00:51, dave wrote: more clearer, this is a more realistic use case: ['awefawef', 'awefawfsf', 'awefsdf', 'zz', 'zz', 'zz'] and the quantity of ''zz'' would be dynamic. Maybe, class Greatest: def __lt__(self, other):

Re: creating an artificial last element in sort list

2012-09-28 Thread Paul Rubin
dave davidrey...@gmail.com writes: What does x need to be to always be last on an ascending sort no matter what 'a' and 'b' are within reason... Why are you trying to do that? It sounds ugly. Just sort the list with the a's and b's. If you absolutely have to, you could make a class with

Re: creating an artificial last element in sort list

2012-09-28 Thread Steven D'Aprano
On Fri, 28 Sep 2012 16:39:33 -0700, dave 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... How about this? a = ['a', 'b'] b = sorted(a) + ['whatever you want'] You could also do this:

Re: creating an artificial last element in sort list

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 6:59 PM, Demian Brecht demianbre...@gmail.com wrote: f = filter(lambda s: s == a[-1], a) That line's assuming that the last element may also be found in arbitrary locations in the list. If it's guaranteed that they're all contiguous at the upper bounds, I'd just walk

Re: creating an artificial last element in sort list

2012-09-28 Thread Demian Brecht
On Fri, Sep 28, 2012 at 8:29 PM, Ian Kelly ian.g.ke...@gmail.com wrote: The slicing operation in the second line assumes that they're all collected at the end of the list anyway. True enough. Hadn't considered otherwise when I first whipped that off with the first example (thinking/trying it