Permutations & Combinations in Python π’
Today I explored how Python handles arrangements & selections with ease.
πΉ Key Concepts:
β’ Permutation (nPr) β Order matters
Example: Arranging ABC β ABC, ACB, BAC...
β’ Combination (nCr) β Order doesnβt matter
Example: Choosing 2 from {A, B, C} β {AB, AC, BC}
πΉ Python Practice:
import itertools
Permutations
print(list(itertools.permutations([1,2,3], 2)))
Combinations
print(list(itertools.combinations([1,2,3], 2)))
β‘ Fun Fact: Permutations & combinations are widely used in probability, cryptography, and even lottery systems π²
Top comments (0)