Skip to content

Instantly share code, notes, and snippets.

@vamsee9
Last active April 17, 2021 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vamsee9/5316f86f33874875b351c201abf20a3a to your computer and use it in GitHub Desktop.
Save vamsee9/5316f86f33874875b351c201abf20a3a to your computer and use it in GitHub Desktop.

Input reading and output formatting #2


Problem Submissions Leaderboard Discussions This problem is designed for you to improvise on how to read input and format the output.

Input Format

The first line of the input contains the value n and k where n is the number of lines in the input and each input line will have k integers.

Constraints

1 <= n <= 100
1 <= k <= 10
Each integer is > 0 and <= 10

Output Format

Find the frequency of each integer and print them in the specific format as follows: Repeat the following for each integer. Integer followed by colon and followed by space and followed by the frequency If there is no frequency for a particular integer, then print empty space for that integer. Check the sample output format.

Sample Input 0

5 5
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 6 7 8 9
Sample Output 0

1: 5
2: 5
3: 5
4: 5
5: 1
6: 1
7: 1
8: 1
9: 1
10: 

Python3 Code

k = input()
a = k.split()
b =[]
for v in range(int(a[0])):
    k = input()
    m = k.split()
    b += m
result = ["1","2","3","4","5","6","7","8","9","10"]
for i in result:
    a = b.count(i)
    if a != 0:
        print(str(i)+": "+str(a))
    else:
        print(str(i)+": "+"")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment