• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Nov 19th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import sys, string
2. d = {}
3. def isletterAthroughZ(letter):
4.     if 65 <= ord(letter) <= 90 or 97 <= ord(letter) <= 122:
5.         return True
6.     else:
7.         return False
8. ## Read lines, split words and for every word add one to count
9. ## negative definitino didnt work with 6th test so I will try positive definition
10. ## go through all characters in line and is if they are letter build newword untill you hit first nonletter
11. newword = ''
12. for line in sys.stdin:
13.     #print(line)
14.     #clearline = ''
15.     for i in line:
16.         if isletterAthroughZ(i):
17.             newword = newword + f'{i}'
18.         elif newword != '':
19.             d[newword] = d.get(newword, 0) +1
20.             newword = ''
21. ## create a list with nested lists each containing word at [0] and word count at [1]
22. ## save the biggest count
23. ArciList = []
24. biggest = 0
25. for key,val in d.items():  ## loop over simoltaneously over keys and items
26.     if val > biggest:
27.         biggest = val
28.     a = []
29.     a.append(key)
30.     a.append(val)
31.     ArciList.append(a)
32. ## Go through all Arcilist[x][1] and for each count biggest:
33. ## 1) print(f'{Arcilist[x][0]} {Arcilist[x][1]}')
34. ## 2) add one to printcount
35. ## 3) after every print check if printcount == 20, if so exit()
36. ## 4) after the loop for count biggest ends, biggest -= 1 and repeat
37. printcount = 0
38. for i in range(biggest,0,-1):
39.     for j in range(len(ArciList)):
40.         if int(ArciList[j][1]) == i:
41.             print(f'{ArciList[j][0]} {ArciList[j][1]}')
42.             printcount += 1
43.             if printcount == 20:
44.                 exit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?