0

Why does it give me an error that tuple object does not support item assignment

L=eval(input('Enter a list: ")) for i in range(len(L)): if L[i]>10: L[i]=10 print(L)

16th Jun 2022, 10:45 AM
Richmond
Richmond - avatar
3 odpowiedzi
+ 2
You are expecting a list so enter a list as [2,3,4,44,4,44,4,7,8,9,3] And you have incorrect matching of quotes '..." . Use " .. " Or ' .. ' but eval() on input not the best way I think.. what is your goal by this code?
16th Jun 2022, 11:20 AM
Jayakrishna 🇮🇳
+ 1
L=eval(input("Enter a list: "))
16th Jun 2022, 10:48 AM
JOKER
JOKER - avatar
+ 1
When you are passing values to 'input', 'eval()' is converting them to tuples and tuples don't support item assignment as they are immutable. why evaluated to tuples? Because you might be supplying values like this: => 6,4,9,5 # without square brackets To get out of this error, you need to convert tuples to list. After taking input, L = list(L)
16th Jun 2022, 2:56 PM
Sandeep
Sandeep - avatar