Noneを消す方法
original_list = [0, None, 1, None, 2, None, 3, None]
filtered_list = [elem for elem in original_list if elem is not None]
print(filtered_list)
出力
[0, 1, 2, 3]
filterを使ってNoneを消す方法
original_list = [0, None, 1, None, 2, None, 3, None]
filtered_list = list(filter(None, original_list))
print(filtered_list)
出力
[1, 2, 3]
0も消えます!