我想在main中運行我的flatten(li)函數,但是當我運行該模塊時它沒有運行。但是當我在shell中輸入「flatten(li)」時它正在工作。有任何想法嗎?謝謝!python main()在shell中不執行
li = [0, 2, [[2, 3], 8, 100, None, [[None]]], -2]
def flatten(li):
i = 0
while i < len(li):
"only execute if the element is a list"
while isinstance(li[i], list):
"""taking the element at index i and sets it as the
i'th part of the list. so if l[i] contains a list
it is then unrolled or 'unlisted'"""
li[i:i + 1] = li[i]
i += 1
for element in li:
if not element and not isinstance(element, int):
li.remove(element)
return li
def main():
flatten(li)
if __name__ == '__main__':
main()
你什麼也看不到,因爲你沒有打印酷 – Copperfield