Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Дан текст. Найдите слово, которое встречается чаще всего.
- #Вариант 1
- words = input().split()
- d = dict()
- for word in words:
- if word in d:
- d[word] += 1
- else:
- d[word] = 1
- max_count_word = ""
- for word in d:
- if max_count_word == "" or (d[word] >= d[max_count_word] and word < max_count_word):
- max_count_word = word
- print(max_count_word)
- #Вариант 2
- a = input().split()
- vocab = {}
- how_common = 0
- for i in a:
- vocab[i] = vocab.get(i,0)+1 #считаем, сколько раз встречается слово
- for i in vocab:
- if vocab[i] > how_common:
- how_common = vocab[i]
- for i in sorted(vocab):
- if vocab[i] == how_common:
- print(i)
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement