How to count the total of all pairs permutations in a list with Python

1 Answer

0 votes
lst1 = [1, 8, 5]

# The pairs are: (1, 8), (1, 5), (8, 1), (8, 5), (5, 1), (5, 8)

total_pairs = len(lst1) * (len(lst1) - 1)
print(f"Total Pairs = {total_pairs}")

lst2 = [1, 8, 5, 2]

# The pairs are: (1, 8), (1, 5), (1, 2), (8, 1), (8, 5), (8, 2),
#                (5, 1), (5, 8), (5, 2), (2, 1), (2, 8), (2, 5)

total_pairs = len(lst2) * (len(lst2) - 1)
print(f"Total Pairs = {total_pairs}")



'''
run:

Total Pairs = 6
Total Pairs = 12

'''

 



answered Jun 18, 2024 by avibootz
...