how to remove 50000 elements from a 100000 list?

Andrew Gwozdziewycz apgwoz at gmail.com
Fri May 5 14:36:08 EDT 2006


It's easy in this case:

     a = range(50000, 100000)

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 50000 elements from a list,which has 100000
> 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:
>>>> a=range(100000)
>>>> b=range(50000)
>>>> 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.
> thanks a lot!
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list

---
Andrew Gwozdziewycz
apgwoz at gmail.com
http://www.23excuses.com
http://ihadagreatview.org
http://and.rovir.us





More information about the Python-list mailing list