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 lessonUse 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
- Flatten a Nested ListBeginner
- Generate All Coin Flip OutcomesIntermediate
- Predict the takewhile OutputIntermediate
- Compute a Running TotalBeginner
- Group Numbers as Even or OddAdvanced
- Fix the groupby BugAdvanced
All Python exercises · 50 practice problems · Standard Library Essentials quiz