Skip to content
Advertisement

function to output pairwise of passed letters

I would like to create a Python function that can take in letters and output a pairwise comparison of the letter given.

So for example, if my function is named pairwise_letters(), then it should behave as follows:

JavaScript

Advertisement

Answer

Use itertools.combinations() to get each pairing. By default, itertools.combinations() outputs an iterable of tuples, which you’ll need to massage a bit to turn into a list of strings:

JavaScript

This outputs:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement