【发布时间】:2021-09-14 07:39:17
【问题描述】:
无论元组项目的顺序如何,如何计算列表中元组的出现次数?例如;
the_list = [
(one, two, three),
(two, three, four),
(one, three, two),
(one, two, three),
(four, two, one),
]
在上面的列表中,我希望 (one, two, three) 和 (one, three, two) 相等并被视为相同的东西。
【问题讨论】:
-
你想使用
permutations,而不是combinations -
您可能想要使用集合或冻结集合而不是元组。如果两个集合包含完全相同的值(无论它们的顺序如何),则它们相等。
标签: python python-3.x list tuples itertools