word-frequency-counter
Source: hackerearth
Difficulty: EASY

You will be provided with a passage (no special characters, no punctuations). Your task is to find the frequency of the words occurring in the text, in other words find the number of times a word occurs in the given passage.
Input
A string with no special characters or punctuations.

Output

Output should be in the format:

Word Count

where Word is a string in the passage, and count is an integer representing number of times the Word has appeared in the passage. Word and the count must be separated by a space.

Words and their count must be listed out in same order as given in the passage.

Passage will be given as a single string, and not in paragraphs.
Constrains

0 ≤ W ≤ 1000

where W is the number of words in the passage.
Note

strings 'apple', 'APPLE', 'Apple' are all considered to be instances of the same word 'APPLE'. In Output, all letters of the words must be converted into UPPERCASE.(Refer Sample Input/Output)

SAMPLE INPUT
My name is Xyz He is Abc Is he allright

SAMPLE OUTPUT
MY 1
NAME 1
IS 3
XYZ 1
HE 2
ABC 1
ALLRIGHT 1

Explanation

In Sample Input: 

My name is Xyz He is Abc Is he allright

'My' is converted into 'MY' to find all other instances of 'My' in the passage easier. MY is present only once in the passage, so the frequency of 'MY' is 1.

'Name' is converted into 'NAME', and its frequency is 1. 

'Frequency of the word 'is' is 3 ('is', 'IS', 'Is' (check passage) ). 'is' is converted into 'IS'. All instances of thee word 'IS' are found from the passage.

Similarly the counting process is done for all other words in the passage.

So the output is:

MY 1
NAME 1    
IS 3    
XYZ 1    
HE 2    
ABC 1    
ALLRIGHT 1


x = input(); a = x.split(); b = [];
for k in range(len(a)):	a[k] = a[k].upper();
for k in a:
	if k.upper() not in b:	b.append(k.upper());
for k in b:	print(k.upper(), a.count(k.upper()));


R = input().split()
for ii in range(len(R)):
	R[ii] = R[ii].upper()
#print R
from collections import Counter
count = Counter(R)
temp = {}
for ii in R:
	if ii not in temp:
		print(ii, count[ii])
		temp[ii] = 1


s=input().strip().split()
dic={}
for i in s:
	temp=i.upper()
	if temp in list(dic.keys()):
		dic[temp]+=1
	else:
		dic[temp]=1

for i in s:
	if i.upper() in list(dic.keys()):
		print(i.upper(),dic[i.upper()])
		del dic[i.upper()]


from collections import Counter

s = list(map(str.upper, input().split()))
d = Counter(s)
for i in s:
	if d[i] != -1:
		print(i, d[i])
		d[i] = -1



from itertools import groupby

words = list(map(str.upper, input().strip().split(' ')))
done = []

freq = [words.count(x) for x in words]


for i in range(0, len(words)):
	if words[i] in done:
		pass
	else:
		print(words[i], freq[i])
		done.append(words[i]) 



wordlist = input().upper().split()
myword = {}
for item in wordlist:
	if(item in myword):
		myword[item] += 1
	else:
		myword[item] = 1
#myword[item] = wordlist.count(item)
for item in wordlist:
	if(item in myword and myword[item] !=0):
		print(item,myword[item])
		myword[item] = 0


s1=input()
s2=s1.upper()
lines=s2.split(' ')
lines2=set(lines)
d={}
for i in lines:
	d[i]=d.get(i,0)+1
for p in lines:
    if d[p]!=0:
        print(p, d[p])
        d[p]=0


#sh

st = input().split()
l= len(st)
for i in range(l):
	st[i] = st[i].upper()

from collections import Counter

count = Counter(st)

temp = {}
for ii in st:
	if ii not in temp:
		print(ii, count[ii])
		temp[ii] = 1


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
x=input()
a=x.split()
b=[]
for k in a:
	if k.upper() in b:
		d=0
		
	else:
		b.append(k.upper())
		

for k in range( len(a)):
	a[k]=a[k].upper()

for k in b:
	print(k.upper(),a.count(k.upper()))


s=input()
s=s.upper()
l=s.split()
dict={}
l1=[]
k=0
for i in l:
	dict[i]=0
for i in l:
	dict[i]=dict[i]+1
	if(i in l1):
		j=1
	else:
		l1.append(i)
		k=k+1
for i in l1:
	print(i,dict[i])
	
	


	




words = [i.upper() for i in input().split()]
visited = []
for word in words:
	if word not in visited:
		print(word + ' ' + str(words.count(word)))
		visited.append(word)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
x=input()
a=x.split()
b=[]
for k in a:
	if k.upper() in b:
		d=0
	else:
		b.append(k.upper())
for k in range(len(a)):
	a[k]=a[k].upper()
for k in b:
	print(k.upper(),a.count(k.upper()))


passage = input()
passage = passage.upper()
stringTokens = passage.split(" ")

wordsOrder = []
wordFrequency = {}

for s in stringTokens:
	if((s in wordFrequency) == False):
		wordFrequency[s] = 1
		wordsOrder.append(s)
	else:
		wordFrequency[s] += 1

for w in wordsOrder:
	print(w + " " + str(wordFrequency[w]))
	


s=input()
s=s.upper()
l=s.split()
dict={}
l1=[]
for i in l:
	dict[i]=0
for i in l:
	dict[i]=dict[i]+1
	if(i in l1):
		j=1
	else:
		l1.append(i)
for i in l1:
	print(i,dict[i])
	
	


	




words = []
frequency = []

ins = [x.upper() for x in  input().split()]
for x in ins:
	if x in words:
		frequency[words.index(x)] +=1
	else:
		words.append(x)
		frequency.append(1)
for a, b in zip(words, frequency):
	print(a, b)


from sys import stdin, stdout

string = input()
string = string.upper()
li = []
new = []
li = string.split()
for x in li:
	word = str(li.count(x))
	if x not in new:
		new.append(x)        
		print(x + " "+word)
		


s=input().upper().split()
while len(s)>0:
	w=s[0]
	c=s.count(w)
	print(w, c)
	for i in range(c):
		del s[s.index(w)]


__author__ = 'shoyeb'

line = input()
line = line.split()
line = [x.upper() for x in line]
d = {}
repeat = []
seq = 0
for i in line:
	a = d.get(i)
	if a is None:
		repeat.append(False)
		a = 1
	else:
		repeat.append(True)
		a = a+1
	d.update({i:a})
	seq = seq + 1

seq=0
for i in line:
	if repeat[seq] == False:
		print(i + " "+str(d.get(i)))
	seq = seq + 1


passage = input()
passage = passage.upper()
stringTokens = passage.split(" ")

wordsOrder = []
wordFrequency = {}

for s in stringTokens:
	if((s in wordFrequency) == False):
		wordFrequency[s] = 1
		wordsOrder.append(s)
	else:
		wordFrequency[s] += 1

for w in wordsOrder:
	print(w + " " + str(wordFrequency[w]))