Bottom Page

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.
Quote
#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)
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Add items from one list to list of lists PUP280 2 308 Mar-28-2020, 08:34 AM
Last Post: PUP280
  adding elements to a list that are more than a specific number Olavv 2 122 Mar-19-2020, 06:05 PM
Last Post: Olavv
  Adding elements to a list by number Olavv 4 188 Mar-08-2020, 11:16 AM
Last Post: ndc85430
  Can't seem to figure out how to put all of the lists items from a loop into 1 list Cosmosso 4 354 Feb-21-2020, 02:40 PM
Last Post: Cosmosso
  List items verification for Integer type vintysaw 4 215 Jan-17-2020, 01:56 PM
Last Post: perfringo
  Access list items in Python kamaleon 2 280 Dec-31-2019, 11:10 AM
Last Post: kamaleon
  Remove all \n from end of list items JackMack118 4 7,789 Dec-27-2019, 08:34 AM
Last Post: perfringo
  Removing duplicate list items eglaud 4 237 Nov-22-2019, 08:07 PM
Last Post: ichabod801
  Adding items in a list (using loops?) Seneca260 6 353 Nov-22-2019, 11:34 AM
Last Post: Seneca260
  Finding MINIMUM number in a random list is not working Mona 5 268 Nov-18-2019, 07:27 PM
Last Post: ThomasL

Forum Jump:


Users browsing this thread: 1 Guest(s)