Assignement in Python with list.extend()
July 31st, 2006
This is weird for me :
d = ['foo', 'bar', 'ba', 'c'] print d f = d f.extend(d) print d
give me the result
-*- mode: compilation; default-directory: “/tmp/” -*-
Compilation started at Mon Jul 31 16:49:41
python “/tmp/a.py”
['foo', 'bar', 'ba', 'c']
['foo', 'bar', 'ba', 'c', 'foo', 'bar', 'ba', 'c']
Compilation finished at Mon Jul 31 16:49:4
It seems that extend assign as well the non extended part (d) which is confusing because to merge list i need to use temporary variable.
Recent Comments