Python Forum

Full Version: counting items in a list of number combinations
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import itertools
numbers = [1,2,3,4,5,6,7,8,9,10]
result = itertools.permutations(numbers,2)
for item in result:
    print (item)
Simple, I know, but escaping me me how to count the permutations of paired numbers in the list created.
I'm sure this is super hacky, but:
import itertools
numbers = [1,2,3,4,5,6,7,8,9,10]
result = itertools.permutations(numbers,2)
total_permutations = 0
for item in result:
    total_permutations += 1
print(total_permutations)
(Feb-19-2020, 07:01 PM)michael1789 Wrote: [ -> ]I'm sure this is super hacky, but:
import itertools
numbers = [1,2,3,4,5,6,7,8,9,10]
result = itertools.permutations(numbers,2)
total_permutations = 0
for item in result:
    total_permutations += 1
print(total_permutations)

import itertools
numbers = [1,2,3,4,5,6,7,8,9,10]
result = itertools.permutations(numbers,2)
count = 0
for item in result:
    print (item)
    count += 1
    print (count)
I just worked it out with the above. Thank you for the reply though.