I'm working on this code for exam in an MIT Python course. It's working but I'm trying to improve it. What could I do, and what should I avoid?
aDict = { 0: 1,
1: 2,
2: 2,
4: 2,
5: 2,
6: 3,
7: 2}
values=list(aDict.values())
keys=list(aDict.keys())
value_copy=values[:]
uniqe=[]
m=0
for value in value_copy:
m+=1
if value in value_copy[m:]:
while(values.count(value)):
try:
values.remove(value)
except:
pass
for val in values:
uniqe.append(keys[value_copy.index(val)])
uniqe.sort()
print (uniqe)
aDict
is ugly, make it pretty. Never use a catch-allexcept
block. Don't use variable names similar to function names or keywords. \$\endgroup\$