本文介绍了在Python中将Frozenset用作对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做两个元素对.我不在乎元素的顺序,因此我使用frozenset.

I would like to make a pair of two elements. I don't care about the order of the elements, so I use frozenset.

我可以想到以下两种方法来使元素从Frozenset迭代回去.有没有更好的方法?预先感谢.

I can think of the following two methods to iterate the elements back from the frozenset. Isn't there any fancier method? Thanks in advance.

pair = frozenset([element1, element2])
pair2 = list(pair)
elem1 = pair2[0]
elem2 = pair2[1]
pair = frozenset([element1, element2])
elems = []
for elem in pair:
    elems.append(elem)
elem1 = elems[0]
elem2 = elems[1]

推荐答案

pair = frozenset([element1, element2])
elem1, elem2 = pair

这篇关于在Python中将Frozenset用作对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 14:04