Can you explain why this code doesn't work:
def flat_list(a):
a = [*a]
b = []
for i in str(a):
if i.isdigit():
b.append(int(i))
return b
print(list(flat_list(iter([1, iter([2, 2, 2]), 4]))))
assert list(flat_list(iter([1, 2, 3]))) == [1, 2, 3]
assert list(flat_list(iter([1, iter([2, 2, 2]), 4]))) == [
1, 2, 2, 2, 4]
assert list(flat_list(iter([iter([2]), iter([4, iter([5, 6, iter([6]), 6, 6, 6]), 7])]))) == [
2, 4, 5, 6, 6, 6, 6, 6, 7]
assert list(flat_list(iter([-1, iter([1, iter([-2]), 1]), -1]))) == [
-1, 1, -2, 1, -1]
Created at: 2022/07/25 17:35; Updated at: 2022/07/27 22:08
The question is resolved.