Python Forum
counting items in a list of number combinations
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
counting items in a list of number combinations
#1
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.
Reply
#2
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)
Reply
#3
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 190 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,343 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Delete strings from a list to create a new only number list Dvdscot 8 1,545 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,222 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Finding combinations of list of items (30 or so) LynnS 1 883 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,610 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,879 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  How to get list of exactly 10 items? Mark17 1 2,533 May-26-2022, 01:37 PM
Last Post: Mark17
  Split a number to list and list sum must be number sunny9495 5 2,298 Apr-28-2022, 09:32 AM
Last Post: Dexty
  how to assign items from a list to a dictionary CompleteNewb 3 1,586 Mar-19-2022, 01:25 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020