简体   繁体   English

在 python 中具有自定义排序的字典

[英]dictionary with custom ordering in python

Is there an available map-like data structure in python that supports custom ordering, insertion and deletion? python 中是否有可用的类似地图的数据结构,支持自定义排序、插入和删除? I want to store (key,value) pairs where keys are int and values are object with many fields so that they are ordered by some particular fields of the value.我想存储(键,值)对,其中键是 int,值是 object,其中包含许多字段,以便它们按值的某些特定字段排序。

i am settled with a dict of (key, val) and a priority queue of tuple (score, key) where score is used for sorting and can be derived from the val object.我使用 (key, val) 的字典和元组 (score, key) 的优先级队列来解决,其中分数用于排序,可以从 val object 派生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM