[英]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.我有一个格式为 name_numberofFrame 的视频的 300 帧,我创建了一个字典,其中键为名称,键为帧数列表,但此列表未排序,我希望对其进行排序以执行其他一些操作。 please provide me a way to sort that list?
请为我提供一种对该列表进行排序的方法?
It's not that difficult.这并不难。 You can access each value inside this dictionary and sort it.
您可以访问此字典中的每个值并对其进行排序。 Like this:
像这样:
a={'a':[4,2,1], 'v':[41,5,1]}
for i,j in a.items():
a[i]=sorted(a[i])
print(a)
Output:输出:
{'a': [1, 2, 4], 'v': [1, 5, 41]}
I hope this is what you were looking for.我希望这就是你要找的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.