Re: Binary Sort on Python List __xor__

2020-06-01 Thread Rhodri James
On 31/05/2020 18:01, Evan Schalton wrote: I think you're arguing both sides of the argument -- numpy arrays do have a lot of similar, related operations (because numpy uses them internally -- since they're more efficient) which means they're not fringe. I'm advocating that the built-in list

Re: Binary Sort on Python List __xor__

2020-05-31 Thread Terry Reedy
On 5/31/2020 12:24 PM, Evan Schalton wrote: I'm less strictly interested in the & operator explicitly working with a bit int, but think it'd be great if the was a built-in filter something like: [1,2,3,4] & [0,0,1,1] => [3,4] OR [1,2,3,4] & [False, False, True, True] = [3,4] Leaving numpy

Re: Binary Sort on Python List __xor__

2020-05-31 Thread Evan Schalton
I think you're arguing both sides of the argument -- numpy arrays do have a lot of similar, related operations (because numpy uses them internally -- since they're more efficient) which means they're not fringe. I'm advocating that the built-in list class add the efficient, convenience methods

Re: Binary Sort on Python List __xor__

2020-05-31 Thread Peter Otten
Evan Schalton wrote: > Peter, > > This isn't a ram consideration as much it's a logical consideration. There > are a lot of ways to handle this, I REALLY don't want to use a package > here. Bit masking is incredibly useful for permutations/combinatoric > algorithms. I can create my own class

Re: Binary Sort on Python List __xor__

2020-05-31 Thread Evan Schalton
Peter, This isn't a ram consideration as much it's a logical consideration. There are a lot of ways to handle this, I REALLY don't want to use a package here. Bit masking is incredibly useful for permutations/combinatoric algorithms. I can create my own class wrapper or functions, and

Re: Binary Sort on Python List __xor__

2020-05-31 Thread Peter Otten
evan.schal...@gmail.com wrote: > I frequently use binary as bool placeholders and find myself filtering > lists based on those bools, this seems to have a similar semantic meaning > as the bit wise ^ or __xor__ operator and could add syntactic sugar to the > base list class. > > Use Case: > >

Re: Binary Sort on Python List __xor__

2020-05-30 Thread Evan Schalton
@MRAB, Yes -- good point, it should be the __and__ operator. do I need a new class? No, but based on this use case and other formatting techniques adding a filter method to the list class that takes in either bit mask or bool list would streamline a lot of code and not change any existing

Re: Binary Sort on Python List __xor__

2020-05-30 Thread MRAB
On 2020-05-30 23:52, evan.schal...@gmail.com wrote: I frequently use binary as bool placeholders and find myself filtering lists based on those bools, this seems to have a similar semantic meaning as the bit wise ^ or __xor__ operator and could add syntactic sugar to the base list class. Use

Binary Sort on Python List __xor__

2020-05-30 Thread evan . schalton
I frequently use binary as bool placeholders and find myself filtering lists based on those bools, this seems to have a similar semantic meaning as the bit wise ^ or __xor__ operator and could add syntactic sugar to the base list class. Use Case: Controlling a stepper at half-step has the

Re: how to sort a hash list without generating a new object?

2011-08-03 Thread Daniel Stutzbach
On Tue, Aug 2, 2011 at 5:53 PM, Chris Rebert c...@rebertia.com wrote: If you /really/ need a sorted mapping datatype, google for sorteddict (which is quite distinct from OrderedDict). Or look for a binary search tree or skip list implementation of some sort; but these aren't commonly used

how to sort a hash list without generating a new object?

2011-08-02 Thread smith jack
the source code is as follows x={} x['a'] = 11 x['c'] = 19 x['b'] = 13 print x tmp = sorted(x.items(), key = lambda x:x[0])# increase order by default, if i want to have a descending order, what should i do? # after sorted is called, a list will be generated, and the hash list x is not

Re: how to sort a hash list without generating a new object?

2011-08-02 Thread Thomas Jollans
On 02/08/11 20:02, smith jack wrote: the source code is as follows x={} x['a'] = 11 x['c'] = 19 x['b'] = 13 print x tmp = sorted(x.items(), key = lambda x:x[0])# increase order by default, if i want to have a descending order, what should i do? # after sorted is called, a list

Re: how to sort a hash list without generating a new object?

2011-08-02 Thread Chris Rebert
mapping datatype, google for sorteddict (which is quite distinct from OrderedDict). Or look for a binary search tree or skip list implementation of some sort; but these aren't commonly used in Python, so it may be hard to find a good one. Cheers, Chris -- http://rebertia.com -- http://mail.python.org

Re: how to sort a hash list without generating a new object?

2011-08-02 Thread Dan Stromberg
for sorteddict (which is quite distinct from OrderedDict). Or look for a binary search tree or skip list implementation of some sort; but these aren't commonly used in Python, so it may be hard to find a good one. I've found a need for such a thing a couple of times. Anyway, here are some other

Re: sort in the list

2005-11-23 Thread Bengt Richter
On Tue, 22 Nov 2005 14:03:32 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote: Shi Mu wrote: I use Python 2.3 to run the following code: a=[[1,2],[4,8],[0,3]] a.sort() a [[0, 3], [1, 2], [4, 8]] I wonder whether the sort function automatically consider the first element in the list of list as

sort in the list

2005-11-22 Thread Shi Mu
I use Python 2.3 to run the following code: a=[[1,2],[4,8],[0,3]] a.sort() a [[0, 3], [1, 2], [4, 8]] I wonder whether the sort function automatically consider the first element in the list of list as the sorting criteria or it just happens to be? Thanks! --

Re: sort in the list

2005-11-22 Thread Fredrik Lundh
Shi Mu wrote: I use Python 2.3 to run the following code: a=[[1,2],[4,8],[0,3]] a.sort() a [[0, 3], [1, 2], [4, 8]] I wonder whether the sort function automatically consider the first element in the list of list as the sorting criteria or it just happens to be? the documentation has the