Seems a standard pattern to me, but you'd know python patterns better than I. result is a dict whose values are sets. If we need to add an ele to one of those, we need to ensure the entry exists first; thus, setdefault sets the entry in the dict to the empty set if it doesn't already have a value. The statement's real purpose is to add an ele to the value.