Re: how to remove 50000 elements from a 100000 list?

2006-05-06 Thread Ju Hui
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

how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Ju Hui
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:

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Diez B. Roggisch
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

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread [EMAIL PROTECTED]
Try to use set objects: a=set(range(10)) b=set(range(5)) a = a - b -- http://mail.python.org/mailman/listinfo/python-list

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Tim Chase
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 =

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Jack Orenstein
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

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Larry Bates
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

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Diez B. Roggisch
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)

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Sion Arrowsmith
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 =

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Ju Hui
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

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Peter Otten
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:

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Andrew Gwozdziewycz
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

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Larry Bates
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: