DEV Community

Aditi Sharma
Aditi Sharma

Posted on

πŸš€ Day 21 of My Python Learning Journey

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 🎲

Python #Maths #100DaysOfCode #ProblemSolving #CodingJourney

Top comments (0)