I have a list like this [1, 2, 3, [4, 5, 6]]
How can I remove [
character inside the list so I can get [1, 2, 3, 4, 5, 6]
?
This is my code so far:
a = [1, 2, 3, [4, 5, 6]]
new_a = []
for item in a:
if len(item) > 1:
for sub_item in item:
new_a.append(sub_item)
else:
new_a.append(item)
print(new_a)
Then I got this error:
TypeError: object of type 'int' has no len()
But when I get the length of the inside list with len(a[3])
, it returns 3
.
How can I fix this?