Why the result of "extended iterable unpacking" with set() is unpredictable? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Why the result of "extended iterable unpacking" with set() is unpredictable? (/thread-27955.html) |
Why the result of "extended iterable unpacking" with set() is unpredictable? - zohanlin - Jun-29-2020 Hello everyone, I want to test "extended iterable unpacking" with set, but the result is unpredictable. d1, *d2, d3 = {1, 2, 3, "a", "acc"} print("d1 =", d1, ", d2 =", d2, ", d3 =", d3) print("type(d1) =", type(d1), ", type(d2) =", type(d2), ", type(d3) =", type(d3))I can get different results as below Quote:d1 = 1 , d2 = [2, 3, 'acc'] , d3 = a Quote:d1 = 1 , d2 = [2, 3, 'a'] , d3 = acc Quote:d1 = acc , d2 = [1, 2, 3] , d3 = a Could somebody tell me what the reason is? RE: Why the result of "extended iterable unpacking" with set() is unpredictable? - buran - Jun-29-2020 because set is unordered collection by definition :-)
RE: Why the result of "extended iterable unpacking" with set() is unpredictable? - zohanlin - Jun-29-2020 I understand what you mean. Thanks a lot! |