# Find the number of occurrences of each number
hashtable={}
for num in nums:
if not num in hashtable:
hashtable[num] = 1
elif num != 0 and hashtable[num] < 2:
hashtable[num] += 1
elif num == 0 and hashtable[num] < 3:
hashtable[num] += 1
# Build a new list of the numbers in the hash table but with no
# more than three occurrences of each number
newlist = []
for num in hashtable: