Skip to content

Instantly share code, notes, and snippets.

@solen003
Created July 18, 2018 09:43
Show Gist options
  • Save solen003/1d5e97855300daaa1c9ae284ea67c94a to your computer and use it in GitHub Desktop.
Save solen003/1d5e97855300daaa1c9ae284ea67c94a to your computer and use it in GitHub Desktop.
Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically. Suppose the following input is supplied to the program: New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3. Then, the output should be: 2:2 3.:1 3?:1 New:1 Python:5 Read:1 and:1 be…
import operator
text_line = input("Type in: ")
freq_dict = {}
for i in text_line.split(' '):
if i.isalpha():
if i not in freq_dict:
freq_dict[i] = 1
elif i in freq_dict:
freq_dict[i] = freq_dict[i] + 1
else:
pass
sorted_freq_dict = sorted(freq_dict.items(), key = operator.itemgetter(0))
print(sorted_freq_dict)
for i in sorted_freq_dict:
print(i[0], i[1])
@silpisingh
Copy link

need for the output

@Vigneshnagarajan-Hexaware

d=dict()
s=input("Enter the string:")
for i in s.split():
d[i]=d.get(i,0)+1
print(d)
print(sorted(d.items()))

@SyamSundarN
Copy link

Sir please give me this program pdfs to practise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment