On Fri, 06 Nov 2009 10:16:58 -0600, Peng Yu wrote: > What is a list-comprehension?
Time for you to Read The Fine Manual. http://docs.python.org/tutorial/index.html > I tried the following code. The list 'l' will be ['a','b','c'] rather > than ['b','c'], which is what I want. It seems 'remove' will disrupt the > iterator, right? I am wondering how to make the code correct. > > l = ['a', 'a', 'b', 'c'] > for x in l: > if x == 'a': > l.remove(x) Oh lordy, it's Shlemiel the Painter's algorithm. Please don't do that for lists with more than a handful of items. Better still, please don't do that. http://www.joelonsoftware.com/articles/fog0000000319.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list