Is Python list.extend () Order Presserving?

I am wondering if the continuation function keeps order in two lists.

>> list = [1, 2, 3] >> list.extend([4, 5]) >> list [1, 2, 3, 4, 5] 

Is an extension always the same way?

+6
source share
1 answer

Yes.

list.extend() simply extends the arguments given at the end of the list.

According to docs :

Expand the list by adding all the elements to this list; equivalent to [len (a):] = L.

So:

 >>> a = [1, 2, 3] >>> a[len(a):] = [4, 5] >>> a [1, 2, 3, 4, 5] 

By the way, do not obscure the built-in type by naming the list list .

+9
source

Source: https://habr.com/ru/post/954910/


All Articles