Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Expand a list by adding slots between each index

Code

my_list = [1, 2, 3, 4]
slot = 0

while(slot <= len(my_list)):
	print(my_list)
	my_list.insert(slot, '.')
	slot += 2

print(my_list)

Output:

Code

[1, 2, 3, 4]
['.', 1, 2, 3, 4]
['.', 1, '.', 2, 3, 4]
['.', 1, '.', 2, '.', 3, 4]
['.', 1, '.', 2, '.', 3, '.', 4]
['.', 1, '.', 2, '.', 3, '.', 4, '.']