clusters[bestmukey].append(x) requires that clusters[bestmukey] already exist and be a list that can be appended to. If clusters does not have the right key, this will raise KeyError.
clusters[bestmukey] = [x] will always work (as long as clusters is a dictionary, which is what I'm assuming), and sets the value to a new list with one element.
The effect of the code is to create a list with a new single value if the key does not already exist, or add the value to the existing list if it does already exist.
The same effect could be achieved without a try/except by using a defaultdict. The defaultdict effectively wraps this logic into itself.
clustersis a dictionary, statement 1 adds an element to avaluethat is a list, if the key, value pair have not been initialized, thekey errorwill be raised; hence, statement 2, which creates a new key, value pair.dict.setdefaultwould probably do the same without thetry/except