回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有下面的代码片段</p>
<pre><code>seta = ["apple","orange","grapes","mango", "starfruit"]
setb = ["papaya","mango","jackfruit","grapes","lychee"]
def setOperation(seta, setb):
union = set(seta) | set(setb)
print(list(union))
intersection = set(seta) & set(setb)
print(list(intersection))
difference = set(seta) - set(setb)
print(list(difference))
difference = set(setb) - set(seta)
print(list(difference))
sdifference = set(seta) ^ set(setb)
print(list(sdifference))
print(list(frozenset(set(seta))))
setOperation(seta,setb)
</code></pre>
<p>每次运行时都会产生不同的输出。
像-</p>
<pre><code>['jackfruit', 'apple', 'mango', 'starfruit', 'grapes', 'lychee', 'orange', 'papaya']
['grapes', 'mango']
['orange', 'apple', 'starfruit']
['jackfruit', 'papaya', 'lychee']
['jackfruit', 'apple', 'starfruit', 'lychee', 'papaya', 'orange']
['orange', 'apple', 'grapes', 'mango', 'starfruit']
</code></pre>
<p>及</p>
<pre><code>
['grapes', 'mango', 'apple', 'orange', 'starfruit', 'lychee', 'papaya', 'jackfruit']
['grapes', 'mango']
['starfruit', 'apple', 'orange']
['lychee', 'papaya', 'jackfruit']
['apple', 'orange', 'starfruit', 'lychee', 'papaya', 'jackfruit']
['grapes', 'starfruit', 'mango', 'apple', 'orange']
</code></pre>
<p>但我希望输出如下-</p>
<pre><code>['apple', 'grapes', 'jackfruit', 'lychee', 'mango', 'orange', 'papaya', 'starfruit']
['grapes', 'mango']
['apple', 'orange', 'starfruit']
['jackfruit', 'lychee', 'papaya']
['apple', 'jackfruit', 'lychee', 'orange', 'papaya', 'starfruit']
</code></pre>
<p>由于顺序的改变,我又一次在一次代码竞赛考试中失败了。
如果我错过了一些简单的事情或者做了一些愚蠢的事情,请一定要告诉我。我要按字典顺序输出。
短暂性脑缺血发作</p>