to Andrew Gwozdziewycz:
Real humor...
Peter Otten:
thanks your reminder, in my project, a will a superset of b.
so symmetric_difference equals difference.
thank you all again!
--
http://mail.python.org/mailman/listinfo/python-list
I want to remove about 5 elements from a list,which has 10
elements.
sample code like below:
a=range(10)
b=range(4)
for x in b:
... a.remove(x)
...
a
[4, 5, 6, 7, 8, 9]
when a and b is small size, it will finished quickly, but when a and b
have many elements.
such as:
Ju Hui wrote:
I want to remove about 5 elements from a list,which has 10
elements.
sample code like below:
a=range(10)
b=range(4)
for x in b:
... a.remove(x)
...
a
[4, 5, 6, 7, 8, 9]
when a and b is small size, it will finished quickly, but when a and b
have many
Try to use set objects:
a=set(range(10))
b=set(range(5))
a = a - b
--
http://mail.python.org/mailman/listinfo/python-list
but when a and b have many elements. such as:
a=range(10)
b=range(5)
for x in b:
... a.remove(x)
...
it will very slowly.
Well, your problem is rather ambiguous. In your examples,
you're removing contiguous ranges. Thus, you should be able
to do something like
a =
On May 5, 2006, at 9:36 AM, Ju Hui wrote:
a=range(10)
b=range(5)
for x in b:
... a.remove(x)
...
it will very slowly. Shall I change to another data structure and
choos
a better arithmetic?
any suggestion is welcome.
If removal is an O(n) operation, then removing 1/2
Ju Hui wrote:
I want to remove about 5 elements from a list,which has 10
elements.
sample code like below:
a=range(10)
b=range(4)
for x in b:
... a.remove(x)
...
a
[4, 5, 6, 7, 8, 9]
when a and b is small size, it will finished quickly, but when a and b
have many
How about a listcomprehension?
new_list = [e for e in old_list if predicate(e)]
# Possibly you need this, too:
old_list[:] = new_list
forgot the predicate. And you should use a set of objects to remove, as then
you'd have O(1) behavior for the in-operator
So:
to_remove = set(b)
Tim Chase [EMAIL PROTECTED] wrote:
Another attempt might be to try
a = [x for x in a if x not in b]
However, this is still doing A*B checks, and will likely
degrade with as their sizes increase.
Combine this with the use of sets others have suggested if the
order of a matters, ie:
bset =
cool!
thanks you all!
I choose
a=set(range(10))
b=set(range(5))
a.symmetric_difference(b)
certainly,the real data not range(), I am satisfied the performance of
set.difference
thank you all again!
--
http://mail.python.org/mailman/listinfo/python-list
Ju Hui wrote:
cool!
thanks you all!
I choose
a=set(range(10))
b=set(range(5))
a.symmetric_difference(b)
certainly,the real data not range(), I am satisfied the performance of
set.difference
thank you all again!
Be warned that this may /add/ items to a:
It's easy in this case:
a = range(5, 10)
But, I'm just trying to add some humor to this thread :)
On May 5, 2006, at 9:36 AM, Ju Hui wrote:
I want to remove about 5 elements from a list,which has 10
elements.
sample code like below:
a=range(10)
b=range(4)
for x in
Peter Otten wrote:
Ju Hui wrote:
cool!
thanks you all!
I choose
a=set(range(10))
b=set(range(5))
a.symmetric_difference(b)
certainly,the real data not range(), I am satisfied the performance of
set.difference
thank you all again!
Be warned that this may /add/ items to a:
13 matches
Mail list logo