Hello I found that in python 3.6:
cnt = collections.Counter(['red', 'blue', 'red', 'green', 'blue', 'blue'])
print(cnt) # >>> Counter({'blue': 3, 'red': 2, 'green': 1})
in the document, it says 'elements() Return an iterator over elements repeating each as many times as its count. Elements are returned in arbitrary order.'
However:
print(list(cnt.elements()))
will always give me:
['red', 'red', 'blue', 'blue', 'blue', 'green']
I don't think it is arbitrary order anymore, it kind of depends on the sequece of original data's occurrence:
cnt = collections.Counter(['red', 'green', 'red', 'blue', 'blue', 'blue'])
print(list(cnt.elements()))
# >>> ['red', 'red', 'green', 'blue', 'blue', 'blue']
If I switch 'blue' and 'green' in the list, I will get 'green' before 'blue' in the cnt.elements()
Is my discovery correct or I was not doing it the right way?