Editor

Find All 2-Letter Permutations

Intermediate · Write the code · from Python itertools: Powerful Tools for Working with Iterables

From the lesson: Python itertools: Powerful Tools for Working with Iterables

Imagine you have a Swiss Army knife for loops. Instead of writing complicated nested loops and temporary lists, you pull out the right tiny tool and the job is done in one clean line.

Read the lesson

Use permutations to find all 2-letter arrangements from the letters ['X', 'Y', 'Z']. Convert the result to a list and print it.

from itertools import permutations
letters = ['X', 'Y', 'Z']
# Find all 2-letter permutations and print

More itertools exercises

All Python exercises · 50 practice problems · Standard Library Essentials quiz