Python相当于java.util.SortedSet? [英] Python equivalent to java.util.SortedSet?

查看:185
本文介绍了Python相当于java.util.SortedSet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道Python是否与Java的SortedSet接口相当?



我要找的是什么:让我说我有一个类型为<$ c的对象$ c> foo ,我知道如何比较两个类型为 foo 的对象,看看是否 foo1 是大于或小于 foo2 。我想要一种在列表 L 中存储许多类型为 foo 的对象的方式,所以每当我遍历列表 L ,我按照我定义的比较方法顺序获取对象。



编辑:



我想我可以使用字典或列表,并且每次修改它时都可以使用 sort(),但这是最好的方式?

解决方案

看看 BTrees 。看起来你需要其中之一。据我所知,您需要的结构将支持将相对较便宜的元素插入存储结构和廉价的排序操作(或甚至缺少)。 BTrees提供了这个。



我有ZODB.BTrees的经验,他们扩展到成千上万的元素。


Does anybody know if Python has an equivalent to Java's SortedSet interface?

Heres what I'm looking for: lets say I have an object of type foo, and I know how to compare two objects of type foo to see whether foo1 is "greater than" or "less than" foo2. I want a way of storing many objects of type foo in a list L, so that whenever I traverse the list L, I get the objects in order, according to the comparison method I define.

Edit:

I guess I can use a dictionary or a list and sort() it every time I modify it, but is this the best way?

解决方案

Take a look at BTrees. It look like you need one of them. As far as I understood you need structure that will support relatively cheap insertion of element into storage structure and cheap sorting operation (or even lack of it). BTrees offers that.

I've experience with ZODB.BTrees, and they scale to thousands and millions of elements.

这篇关于Python相当于java.util.SortedSet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆