<分区>
所以我有一个带有值的字典:[假设没有重复项]
mydict={0: 1, 1: 2, -2: -1, -1: 0, -3: -2}
我想要做的是使用值获取它们的键,因此如果给出 1,我希望它获取值为 1 的键,即 0,并将其附加到列表中。
finalO=[]
if x in myddict.values():
finalO.append([mydict.**getKeyByVal**(x)])--> so is there's a built in function that will allow me to do that?
我不想做一个 for 循环,因为我想在线性时间内完成它。