Answer the question
In order to leave comments, you need to log in
Why are the values from the loop not saved?
Hello)
S1 = 'Зайцы и пчелы прыгают по лужку'
lenght = 5
res = S1.split()
for i in res:
if len(i) == lenght:
i = i[:-3]
print (i)
print(res)
Answer the question
In order to leave comments, you need to log in
Hi, the i variable does not refer to res. Each iteration of the loop i is assigned the value of an element from res.
In order to overwrite values in res, you need to access res directly.
For example something like this
S1 = 'Зайцы и пчелы прыгают по лужку'
lenght = 5
res = S1.split()
for i in range(len(res) - 1):
if len(res[i]) == lenght:
res[i] = res[i][:-3]
print (res[i])
print(res)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question