Hello! Help needed: введите сюда код
list = ['0', '1'] res = [] def a(a): list[0] = a return list def x(): for i in range(5): a(i) print(a(i)) res.append(a(i)) print(res) It is necessary that the res list contains in the finals a list of possible options for the list, which for some reason does not occur, although on print a (i) everything looks correct. I do not understand what's the matter. How do you need to correctly put the values in the list res, in order to get [[0, '1'], [1, '1'], [2, '1'], [3, '1'], [4, 'one']]?
So, with this question sort of figured out, the decision was to determine the list inside the function. And if the task became more complicated, and you need to work 2 functions at once with this list? there is no way to do without a global variable, and this again returns to the beginning. Here is a corrected code and a new task)
lst = ['0', '1'] def a(one): lst[0] = one return lst def b(two): lst[1] = two return lst def x(): rng = range(5) res = [] for i in rng: a(i) for j in rng: b(j) res.append(lst) print(res) x()