Python Forum

Full Version: Why the result of "extended iterable unpacking" with set() is unpredictable?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
type(d1) = <class 'int'> , type(d2) = <class 'list'> , type(d3) = <class 'str'>

Quote:d1 = 1 , d2 = [2, 3, 'a'] , d3 = acc
type(d1) = <class 'int'> , type(d2) = <class 'list'> , type(d3) = <class 'str'>

Quote:d1 = acc , d2 = [1, 2, 3] , d3 = a
type(d1) = <class 'str'> , type(d2) = <class 'list'> , type(d3) = <class 'str'>

Could somebody tell me what the reason is?
because set is unordered collection by definition :-)
I understand what you mean.
Thanks a lot!