Answer the question
In order to leave comments, you need to log in
How to change a value in an array in Python?
There is a dictionary and an array:
list = [{"1": [1, 2]}]
And how to add a value to the list dictionary?
Tried doing .update and += and = : list["1"].update(3) and list["1"] += [3] and list["1"] = [3], but it worked:
[{ "1": [1, 2, [], 3]}]
Please help.
Answer the question
In order to leave comments, you need to log in
change value in array
add value to list dictionary
list[0]['1'].append(3)
It's not entirely clear what you need to end up with:
lst = [{"1": [1, 2]}] # называть переменную list - плохая практика
lst[0]['1'].append(3)
print(lst)
# [{'1': [1, 2, 3]}]
lst[0]['2'] = [4, 5]
print(lst)
# [{'1': [1, 2, 3], '2': [4, 5]}]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question