Bits of Python Information

Do not use mutable types as default parameter

Default argument values are evaluated only once during function definition at module load time. If you don't provide an argument to function with default parameter value, you don't get what you expect from your default parameter.
The fix is to set the keyword argument to None, and initialize it inside the function definition.

def func(data=[]):
    data.extend([num for num in range(3)])

    for item in data:
        print(item, end=' ')

func()
# Output: 0 1 2

func()
# Output: 0 1 2 0 1 2

def func(data=None):
    
    if data is None:
        data = []

    data.extend([num for num in range(3)])

    for item in data:
        print(item, end=' ')

func()
# Output: 0 1 2

func()
# Output: 0 1 2

func([1,2,3])
# Output: 1 2 3 0 1 2

Do not write Python as C

Developers that have C/C++ background can write python code as C in first times. You should avoid this for writing more readable, faster, and pythonic code.

# instead of writing a loop like
for index in range(len(a_list)):
    print(a_list[index])

# write like 
for item in a_list:
    print(item)

# if you also need the index of item you can use enumerate
for index, item in enumerate(a_list):
    print(index, item)