我对python的字典有问题。在import random
values = {"A" : [2,3,4], "B" : [2], "C" : [3,4]}
# this variable have to store as keys all the values in the lists kept by the variable values, and as values a list of numbers
# example of dictionary :
# {"2" : [2, 6 ,7 ,8, 8], "3" : [9, 7, 6, 5, 4], "4" : [9, 7, 5, 4, 3]}
dictionary = {}
for x in values.keys():
listOfKeyX = values[x]
newValues = []
for index in range (0, 5):
newValue = random.randint(0,15)
newValues.append(newValue)
for value in listOfKeyX:
if value in dictionary.keys():
for index in range (0, 5):
#i want to update a value in dictionary only if the "if" condition is satisfied
if(newValues[index] < dictionary[value][index]):
dictionary[value][index] = newValues[index]