for i in list - change a list inside a for loop?
John Hunter
jdhunter at ace.bsd.uchicago.edu
Mon Mar 3 09:50:18 EST 2003
>>>>> "Albert" == Albert Hofkamp <hat at se-46.wpa.wtb.tue.nl> writes:
Albert> This is very clear code, and since Python does reference
Albert> counting the elements are not really copied, so speed
Albert> should be managable.
A couple of alternatives that should be faster:
>>> x = ['A', 'B', 'C', 'D']
>>> filter(lambda arg: arg!='C', x)
['A', 'B', 'D']
>>> [arg for arg in x if arg != 'C']
['A', 'B', 'D']
John Hunter
More information about the Python-list
mailing list