Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 87449ec

Browse files
Add files via upload
1 parent c9025c9 commit 87449ec

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

‎Word Order.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# You are given words. Some words may repeat. For each word, output its number of occurrences. The output order should correspond with the input order of appearance of the word. See the sample input/output for clarification.
2+
3+
# Note: Each input line ends with a "\n" character.
4+
5+
# Constraints:
6+
7+
# The sum of the lengths of all the words do not exceed
8+
# All the words are composed of lowercase English letters only.
9+
10+
# Input Format
11+
12+
# The first line contains the integer, .
13+
# The next lines each contain a word.
14+
15+
# Output Format
16+
17+
# Output lines.
18+
# On the first line, output the number of distinct words from the input.
19+
# On the second line, output the number of occurrences for each distinct word according to their appearance in the input.
20+
21+
# Sample Input
22+
23+
# 4
24+
# bcdef
25+
# abcdefg
26+
# bcde
27+
# bcdef
28+
# Sample Output
29+
30+
# 3
31+
# 2 1 1
32+
# Explanation
33+
34+
# There are distinct words. Here, "bcdef" appears twice in the input at the first and last positions. The other words appear once each. The order of the first appearances are "bcdef", "abcdefg" and "bcde" which corresponds to the output.
35+
36+
37+
38+
39+
n = int(input())
40+
list1 = []
41+
dicti = {}
42+
for i in range(0,n):
43+
list1.append(input())
44+
45+
for i in list1:
46+
if i in dicti:
47+
dicti[i] += 1
48+
else:
49+
dicti[i] = 1
50+
51+
print(len(dicti))
52+
for i in dicti:
53+
print(dicti[i],end=" ")
54+
55+
56+
57+
58+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /