• Flatten a List on O'Reilly

 

I would like to give some feedback about https://py.checkio.org/mission/flatten-list/legacy-solve/ ... it appears the system only starts new and fresh locally inside the defined function. The variable I've assigned outside the function maintains its value from the last assertion test.

I tried to rectify this issue by making the variable global, but to no avail. The solution works in an IDE, obviously, in my case, I'm using PyCharm. Is this not a valid or acceptable way to complete this particular challenge? The code I used is as follows:

nums = []


def flat_list(array):
    for item in array:
        if type(item) is list:
            flatten(item)
        elif type(item) is int:
            nums.append(item)
    return nums

I've included some screenshots showing the different output from my end. The function name and variable names have been changed to protect the innocent :P

HTTP_USER_AGENT:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36