# How to generate all permutations of a list in Python?

PythonProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

You can use the itertools package's permutations method to find all permutations of a list in Python. You can use it as follows −

## Example

import itertools
perms = list(itertools.permutations([1, 2, 3]))
print(perms)

## Output

This will give the output −

[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
Updated on 05-Mar-2020 10:20:55