擅长:python、mysql、java
<p>您的标题和示例相互冲突。您应该查阅关于<a href="https://docs.python.org/3/library/stdtypes.html?highlight=set#set" rel="nofollow noreferrer">set</a>、<a href="https://docs.python.org/3/library/stdtypes.html?highlight=tuple#tuple" rel="nofollow noreferrer">tuple</a>和<a href="https://docs.python.org/3/library/stdtypes.html?highlight=tuple#list" rel="nofollow noreferrer">list</a>的python文档</p>
<p>一些例子:</p>
<pre><code>a_list = ['b', 'c', 'a']
a_tuple = ('b', 'c', 'a')
a_set = {'b', 'c', 'a'}
a_list_of_tuples = [('b', 'c', 'a'), ('b', 'c'), ('a', 'b')]
a_list_of_tuples_and_lists = [('b', 'c', 'a'), [('b', 'c'), ('a', 'b')]]
</code></pre>
<p>此示例适用于列表/元组列表和集合/元组的元组,但它返回的是实际的元组列表<strong>而不是预期输出示例中提供的集合元组</p>
<pre><code>my_list = [('b', 'c', 'a'), [('b', 'c'), ('a', 'b')]]
print(tuple((sorted(item) for item in my_list)))
-> (['a', 'b', 'c'], [('a', 'b'), ('b', 'c')])
my_tuple = ({'b', 'c', 'a'}, {('b', 'c'), ('a', 'b')})
print(tuple((sorted(item) for item in my_tuple)))
-> (['a', 'b', 'c'], [('a', 'b'), ('b', 'c')])
</code></pre>