Basic numeric list
Input
generate_pairs([1, 2, 3])
Output
[(1, 2), (1, 3), (2, 3)]
All unordered pairs from [1,2,3] in combination order.
Full lesson preview
Produce all unordered 2-element combinations from a list while preserving input order. Use itertools.combinations for concise code.
Problem statement
Task
Examples
Input
generate_pairs([1, 2, 3])
Output
[(1, 2), (1, 3), (2, 3)]
All unordered pairs from [1,2,3] in combination order.
Input format
Output format
Constraints
Samples
Input
generate_pairs(['a', 'b', 'c', 'd'])
Output
[('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd'), ('c', 'd')]
All unordered pairs from the list of characters.