You can use a single line interface with word understanding and list comprehension:
result = { k :[vi for vi in v if k != vi] for k,v in jumps.items()}
This leads to:
>>> {k:[vi for vi in v if k != vi] for k,v in jumps.items()} {'T8': ['T6', 'S6'], 'I6': ['H6', 'I5']}
Note that you will remove all items from lists that are equal to the key. In addition, the removal process is performed for everyone .
The code works as follows: we iterate over each key-value pair k,v in the jumps dictionary. Then for each such pair we build the key in the resulting dictionary and associate [vi for vi in v if k != vi] . This is an understanding of the list, where we filter out all the values ββof v that are equal to k . Thus, only vi (in that order) k != vi remains.
Willem van onsem
source share