Ich verstehe, dass Wörterbuch nicht geordnet ist. Ich weiß das.In welcher Reihenfolge zeigt Python den Schlüssel des Wörterbuchs
Dies ist jedoch ein Code zum Zählen der Worthäufigkeit.
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]))
Ich rief die WordCount mit der folgenden Zeichenfolge.
kann ein Wort einmal erscheinen, aber zweimal zweimal erscheinen, da dies ein nicht wieder mit diesem Tier erscheint
Dies ist das Ergebnis.
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.
Ich verstehe, dass nicht bestellt, aber selbst wenn sie nicht bestellt werden, warum die Reihenfolge anders ist? Meine Phantasie ist der Grund, dass es nicht alphabetisch geordnet ist, weil die Reihenfolge auf der Zeit basiert sie registriert sind (dh.queue)
Ich kann mir nicht vorstellen, dass sie random.shuffle() aufrufen, wenn ich es anzeigen möchte.
Der nächste Mal versuchen, Ihre Frage Titel in eine Google-Suche einfügen, bevor es zu veröffentlichen. Sie können oft nützliche Ergebnisse wie folgt erhalten. – TigerhawkT3