def pop_key(data):
 items = sorted(data.items(), key=(lambda item: (len(item[1]), item[0])))
 key = items[0][0]
 data.pop(key)
 for dep in data.values():
  dep.discard(key)
 return key

def pop_key ( data ) : items = sorted ( data . items ( ) , key = ( lambda item : ( len ( item [ 1 ] ) , item [ 0 ] ) ) ) key = items [ 0 ] [ 0 ] data . pop ( key ) for dep in data . values ( ) : dep . discard ( key ) return key
pop an item from the graph that has the fewest dependencies in the case of a tie the winners will be sorted alphabetically .