why bother
people = ((data["name"],data["number"]) for data in json.loads(some_list)[::-1])
phoneBook = dict(people)
this will run in reverse order through the list so the first occurrence of the name will be the one stored in the dictionary
it takes longer to check than to just insert it ... even if it ends up over written
to answer your question however
your original code did not work because your else was inside the forloop essentially adding the entry if any name in the book did not match the name being inserted
you can fix it easily enough, by exiting the function when a match is found... and not adding the name to the dictionary until you have checked all names
phoneBook = dict()
def addNumber(name, number):
for i in phoneBook:
if i == name:
print 'error'
return
phoneBook[name] = number
addNumber("james",56)
addNumber("Tommy",26)
addNumber("james",77)