# Check if two iterables are permutations of each other

Check if two iterables are permutations of each other.

• Use len to check if both iterables have the same length.
• Use Counter to verify that each element appears an equal number of times in both iterables.
from collections import Counter

def is_perm(items0, items1):
return len(items0) == len(items1) and Counter(items0) == Counter(items1)

is_perm([1, 2, 3], [4, 1, 6]) # False
is_perm([1, 2], [2, 1]) # True

is_perm("snack", "track") # False

## More like this

• Collection · 28 snippets

### Python Strings

Learn how to format and manipulate strings in Python 3.6 with this snippet collection.

• Python ·

### Test if some list elements are truthy

Checks if the provided function returns True for at least one element in the list.

• Python ·

### Check if list elements are identical

Checks if all elements in a list are equal.

• Python ·

### Merge lists

Merges two or more lists into a list of lists, combining elements from each of the input lists based on their positions.

Start typing a keyphrase to see matching snippets.