from collections import Counter
from itertools import chain

def sortPairList2(data):
    tally = Counter(chain(*map(set, data)))
data.sort(key=lambda x: sorted(tally[i] for i in x))
Sorting a list pairs by frequency of the pair elements