Monday, March 18, 2013

Difference between "list.extend" and "list+list"

list extend:
any thing iterable will do for the extend like


>>> li=[1,2,3]
>>> li.extend({4:5,6:7})
>>> li
[1, 2, 3, 4, 6]
>>>
But list concatenate can not do this.

list.extend does not need to copy the original list, so if a very long list concatenate a small list, it is better to use list.extend.


No comments:

Post a Comment