hitung nomor setiap item dalam daftar python
word_counter = {}
book_title = ['great', 'expectations','the', 'adventures', 'of', 'sherlock','holmes','the','great','gasby','hamlet','adventures','of','huckleberry','fin']
for word in book_title:
if word not in word_counter:
word_counter[word] = 1
else:
word_counter[word] += 1
print(word_counter)
# output - {'great': 2, 'expectations': 1, 'the': 2, 'adventures': 2, 'of': 2, 'sherlock': 1, 'holmes': 1, 'gasby': 1, 'hamlet': 1, 'huckleberry': 1, 'fin': 1}
Rajitha Amarasinghe