I understand that dictionary is not ordered. I know that.
However, this is a code of counting word frequency.
def wordCount(kalimat):
counter = {}
for kata in kalimat.split(" "):
if kata in counter:
counter[kata] += 1
else:
counter[kata] = 1
for I in sorted(counter):
if counter[I] == 1:
print("{:<10} appears 1 time.".format(I,counter[I]))
else:
print("{:<10} appears {:<3} times.".format(I,counter[I]))
I called the wordCount with the following string.
A word may appear once but twice may appear twice since this one will not appear again with this animal
This is the result.
Run #1
again appears 1 time.
not appears 1 time.
one appears 1 time.
may appears 2 times.
word appears 1 time.
appear appears 3 times.
since appears 1 time.
twice appears 2 times.
but appears 1 time.
with appears 1 time.
will appears 1 time.
A appears 1 time.
animal appears 1 time.
this appears 2 times.
once appears 1 time.
Run #2
once appears 1 time.
word appears 1 time.
will appears 1 time.
animal appears 1 time.
appear appears 3 times.
again appears 1 time.
A appears 1 time.
not appears 1 time.
one appears 1 time.
but appears 1 time.
twice appears 2 times.
may appears 2 times.
with appears 1 time.
since appears 1 time.
this appears 2 times.
I understand that is not ordered, but even if they are not ordered, why the order is different? My imagination is the reason it's not alphabetically ordered because the order is based on the time they are registered (ie.queue)
I can't imagine that they call random.shuffle() when I want to display it.