Skip to content

Instantly share code, notes, and snippets.

@BurhanH
Created February 22, 2019 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BurhanH/ec3585fac34d2849dbe4fb2695c2862d to your computer and use it in GitHub Desktop.
Save BurhanH/ec3585fac34d2849dbe4fb2695c2862d to your computer and use it in GitHub Desktop.
itertools examples
# -*- coding: utf-8 -*-
from itertools import permutations, combinations, chain
for p in permutations([1, 2, 3]):
print(p)
# (1, 2, 3)
# (1, 3, 2)
# (2, 1, 3)
# (2, 3, 1)
# (3, 1, 2)
# (3, 2, 1)
for c in combinations([1, 2, 3, 4], 2):
print(c)
# (1, 2)
# (1, 3)
# (1, 4)
# (2, 3)
# (2, 4)
# (3, 4)
for ch in chain(range(3), range(12, 15)):
print(ch)
# 0
# 1
# 2
# 12
# 13
# 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment