python - sort list of integers that are value to a key in dictionary python
问题描述
i have a 300 frames from a video in format name_numberofFrame, i created a dictionary with key as name and value to key as list of number of frame but this list is not sorted i want it to be sorted to perform some other operations. please provide me a way to sort that list?
解决方案
这并不难。您可以访问此字典中的每个值并对其进行排序。像这样:
a={'a':[4,2,1], 'v':[41,5,1]}
for i,j in a.items():
a[i]=sorted(a[i])
print(a)
输出:
{'a': [1, 2, 4], 'v': [1, 5, 41]}
我希望这就是你要找的。