简体   繁体   English

对frozensets列表进行排序?

[英]Sorting a list of frozensets?

Is it possible to lexicographically sort a list of frozensets as in the following example:是否可以按字典顺序对冻结集列表进行排序,如下例所示:

sort_frozensets(frozenset(['d','b']), frozenset(['a','b']), frozenset(['z','a']), frozenset(['l',''m]))
#result = frozenset(['a','b']), frozenset(['z','a']), frozenset(['d','b']), frozenset(['l',''m])

So, it's ordered through the order of the first item, and if the first item is the same, then the second item is considered.因此,它通过第一项的顺序进行排序,如果第一项相同,则考虑第二项。

No, frozensets do not have an order, so you can't sort them.不,frozensets 没有顺序,因此您无法对它们进行排序。 Find another data structure that fits your problem, we won't be able to guess it.找到适合您问题的另一种数据结构,我们将无法猜测。

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

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