I need to solve the below problem using looping.
Statement
Your input is a list of lists with unknown nesting level. Could be like:
[
[1, 2],
[
3,
[4, 5],
],
6,
7,
]
Your challenge is to reshape it into a single list like that:
[1, 2, 3, 4, 5, 6, 7]
My code is :
import json
data = json.loads(input())
#WRITE YOUR CODE HERE
list_data = list(data)
flat_list = [item for items in list_data for item in items]
print(flat_list)
TypeError: 'int' object is not iterable