Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print('Adding string character with total in dictionary')
- string = 'hi mr partho yesterday was the 9th class and that class environment was really nice thank you'
- counts = dict()
- for line in string:
- words = line.split()
- for word in words:
- if word not in counts:
- counts[word] = 1
- else:
- counts[word] += 1
- print(counts)
- print('Sort the dictionary by bigger value till 8 nos value')
- lst = list()
- for key, val in list(counts.items()):
- lst.append((val, key))
- lst.sort(reverse=True)
- for key, val in lst[:8]:
- print(key, val)
- print('Sort the dictionary by smaller value from third smaller value')
- lst = list()
- for key, val in list(counts.items()):
- lst.append((val, key))
- lst.sort(reverse=False)
- for key, val in lst[3:10]:
- print(key, val)
- print('Calculate avarage by list')
- numlist = list()
- count=0
- while (True):
- inp = input('Enter a number till to enter done: ')
- if inp == 'done': break
- else :
- try:
- value = float(inp)
- except:
- print('Invalid input')
- continue
- numlist.append(value)
- count =count+1
- average = sum(numlist) / count
- print('Average:', average)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement