My code if to flatten a shllow list:- I am getting an error of
int object is not subscriptable
l = eval(input("Enter a nested list : "))
a = len(l)
for x in range(0,a):
a[x]+=a[x]
print(l)
First take the input as a string by str() then after you have stored it in l, convert it to a list using the list().
You can also directly convert the input to a list by list(input("text"))
a = len(l)a is an integer.a[x]makes no sense. Did you meanl[x]?input. You probably meanl[x]instead ofa[x].evalis dangerous to use with user inputs.input()meanteval(input()). Looking backwards it was almost stupid :) Although, I'd sayevalis pretty fine as long as it doesn't appear in production code, and is used as a way to quickly test language features. That said, if the goal is just to parse some nested list of integers, floats, or strings,json.loads(input())might be best.