Elektrine lite

← Feed

@davidruffner@raphus.social

Post #2386756

2026-05-07 02:01 UTC

I learned today from a coworker that in python you can use slice indexing to insert a list into another list. For example: ``` a = [0,1,2,3] b = [8,9] a[1:1] = b print(a) # [0, 8, 9, 1, 2, 3] ``` It works but seems strange to me. It makes sense that the index 1 position of the `a` list gets filled in with the first entry from the `b` list, but then this previously index 1 value is remembered and gets appended to the end of the `b` list. It's not obvious to me. I intend to look into the implementation to see how it works under the hood. #TIL #python

Replies (2)