Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Python集合内包表記の学習を始めたばかりです。注文したのではなく{ 2**x for x in {0,1,2,3,4} }返品するのはなぜですか?{8, 1, 2, 4, 16}{1, 2, 4, 8, 16}
{ 2**x for x in {0,1,2,3,4} }
{8, 1, 2, 4, 16}
{1, 2, 4, 8, 16}
数学的に言えば、集合には順序がありません。セットを表示または反復する場合、Python は明らかに特定の順序を提供する必要がありますが、この順序は任意であり、依存するものではありません。ただし、順序は特定のセットに対して固定されています。変更されていない同じセットを反復すると、毎回同じ順序が生成されます。