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]
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)
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
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,
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
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
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
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
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
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
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:
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
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.
--
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
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])
[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
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
17 matches
Mail list logo