Given a list of friends how many pairs can be formed? #Python's itertools.combinations is your friend:

>>> friends = 'bob tim julian fred'.split() >>> list(itertools.combinations(friends, 2)) [('bob', 'tim'), ('bob', 'julian'), ('bob', 'fred'), ('tim', 'julian'), ('tim', 'fred'), ('julian', 'fred')]