Advertisement
muhammad_nasif

TASK_12

Apr 16th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. def atMaxTwo(inputList):
  2.     dictionary = {}
  3.     for key in inputList:
  4.         if key in dictionary.keys():
  5.             dictionary[key] += 1
  6.         else:
  7.             dictionary[key] = 1
  8.     newList = []
  9.     counter = 0
  10.     for key, value in dictionary.items():
  11.         if value > 2:
  12.             counter += (value - 2)
  13.             dictionary[key] = value - 2
  14.  
  15.         for i in range(0, dictionary[key]):
  16.             newList.append(key)
  17.  
  18.     print("Removed: "+str(counter))
  19.     return newList
  20.  
  21.  
  22. lst = atMaxTwo([10, 10, 15, 15, 20])
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement