Re: ordered sets operations on lists..

2006-02-12 Thread Bengt Richter
On Sat, 11 Feb 2006 10:24:04 -0800, [EMAIL PROTECTED] (Alex Martelli) wrote: Raymond Hettinger [EMAIL PROTECTED] wrote: ... The intersection step is unnecessary, so the answer can be simplified a bit: filter(set(l2).__contains__, l1) [5, 3] filter(set(l1).__contains__, l2) [3, 5]

Re: ordered sets operations on lists..

2006-02-12 Thread Alex Martelli
Bengt Richter [EMAIL PROTECTED] wrote: ... Personally, I'd always use (depending on guesses regarding lengths of lists) [x for x in l1 if x in l2] or the setified equivalent, of course. Perhaps newbies should be advised that [x for x in l1 if x in set(l2)] is not a (well)

Re: ordered sets operations on lists..

2006-02-12 Thread Steve Holden
Alex Martelli wrote: Bengt Richter [EMAIL PROTECTED] wrote: ... Personally, I'd always use (depending on guesses regarding lengths of lists) [x for x in l1 if x in l2] or the setified equivalent, of course. Perhaps newbies should be advised that [x for x in l1 if x in set(l2)] is

Re: ordered sets operations on lists..

2006-02-12 Thread Felipe Almeida Lessa
Em Dom, 2006-02-12 às 23:15 -0500, Steve Holden escreveu: Given that Python 2.4 doesn't even perform simple constant folding for arithmetic expressions [snip] May I ask why doesn't it perform such optimization? Is there any special difficulties in doing so with the Python compiler? Also,

Re: ordered sets operations on lists..

2006-02-12 Thread Steve Holden
Felipe Almeida Lessa wrote: Em Dom, 2006-02-12 às 23:15 -0500, Steve Holden escreveu: Given that Python 2.4 doesn't even perform simple constant folding for arithmetic expressions [snip] May I ask why doesn't it perform such optimization? Is there any special difficulties in doing so

RE: ordered sets operations on lists..

2006-02-12 Thread Delaney, Timothy (Tim)
Steve Holden wrote: The basic answer is that so far no developer has felt it worthwhile to expend time on adding these optimizations. Mainly because it's rare to find such constructs in anything except contrived examples ... Nearly every time you use a literal, it's being added to (subtracted

Re: ordered sets operations on lists..

2006-02-12 Thread Felipe Almeida Lessa
Em Dom, 2006-02-12 às 23:51 -0500, Steve Holden escreveu: The basic answer is that so far no developer has felt it worthwhile to expend time on adding these optimizations. I always thought these small optimizations could lead Python to be faster overall. I remember about this every time I see

RE: ordered sets operations on lists..

2006-02-12 Thread Delaney, Timothy (Tim)
Delaney, Timothy (Tim) wrote: Adding such optimisations to Python may improve it's benchmark scores, Blegh! Time to give myself a good kicking! Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list

Re: ordered sets operations on lists..

2006-02-12 Thread Steve Holden
Felipe Almeida Lessa wrote: Em Dom, 2006-02-12 às 23:51 -0500, Steve Holden escreveu: The basic answer is that so far no developer has felt it worthwhile to expend time on adding these optimizations. I always thought these small optimizations could lead Python to be faster overall. I

Re: ordered sets operations on lists..

2006-02-12 Thread Brett Cannon
On 2/12/06, Felipe Almeida Lessa [EMAIL PROTECTED] wrote: Em Dom, 2006-02-12 às 23:15 -0500, Steve Holden escreveu: Given that Python 2.4 doesn't even perform simple constant folding for arithmetic expressions [snip] May I ask why doesn't it perform such optimization? Is there any special

Re: ordered sets operations on lists..

2006-02-12 Thread Kay Schluehr
Bengt Richter wrote: Perhaps newbies should be advised that [x for x in l1 if x in set(l2)] But the resulting list is a representative of bag not a set ( contains multiple occurrences of elements ): [x for x in [3, 3] if s in Set([3])] [3,3] Same with Raymonds solution:

Re: ordered sets operations on lists..

2006-02-11 Thread Alex Martelli
Raymond Hettinger [EMAIL PROTECTED] wrote: ... The intersection step is unnecessary, so the answer can be simplified a bit: filter(set(l2).__contains__, l1) [5, 3] filter(set(l1).__contains__, l2) [3, 5] ...and if one has time to waste, setification being only an optimization, it can

ordered sets operations on lists..

2006-02-10 Thread Amit Khemka
Hello, Is there a *direct* way of doing set operations on lists which preserve the order of the input lists ? For Ex. l1 = [1, 5, 3, 2, 4, 7] l2 = [3, 5, 10] and (l1 intersect l2) returns [5, 3] (and (l2 intersect l1) returns [3, 5]) thanks in advance, amit. --

Re: ordered sets operations on lists..

2006-02-10 Thread bonono
Amit Khemka wrote: Hello, Is there a *direct* way of doing set operations on lists which preserve the order of the input lists ? For Ex. l1 = [1, 5, 3, 2, 4, 7] l2 = [3, 5, 10] and (l1 intersect l2) returns [5, 3] (and (l2 intersect l1) returns [3, 5]) what do you

Re: ordered sets operations on lists..

2006-02-10 Thread Scott David Daniels
Amit Khemka wrote: Hello, Is there a *direct* way of doing set operations on lists which preserve the order of the input lists ? Nope For Ex. l1 = [1, 5, 3, 2, 4, 7] l2 = [3, 5, 10] and (l1 intersect l2) returns [5, 3] (and (l2 intersect l1) returns [3, 5])

Re: ordered sets operations on lists..

2006-02-10 Thread Raymond Hettinger
[Amit Khemka] Hello, Is there a *direct* way of doing set operations on lists which preserve the order of the input lists ? For Ex. l1 = [1, 5, 3, 2, 4, 7] l2 = [3, 5, 10] and (l1 intersect l2) returns [5, 3] (and (l2 intersect l1) [bonono] what do you mean

Re: ordered sets operations on lists..

2006-02-10 Thread bonono
Raymond Hettinger wrote: The intersection step is unnecessary, so the answer can be simplified a bit: filter(set(l2).__contains__, l1) [5, 3] filter(set(l1).__contains__, l2) [3, 5] stand corrected. -- http://mail.python.org/mailman/listinfo/python-list