Python Forum
Do something with all possible combinations of a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do something with all possible combinations of a list
#1
Going to explain in simple language since googling this didn't really help me (unsure how to name this problem).

I have a list which items I want to check with eachother. Each combination triggers a function.
So a list with [1,2,3] should run a function for pair [1,2], for pair [1,3] and for pair [2,3]. Duplicates / themselves aren't needed [1,1] [2,1] [2,2] [3,1] [3,2]

My list might become huge (600K (if that is huge)) so I 'Yield' seems interesting too.

Below is my soup. Horrible, not logical, returns duplicates (I know Sick ).
listA = [1,2,3,4,5,6]
listB = listA[:]
output = []
for a in listA:	
	for b in listB:
		if b != a:
            //function here
			output.append([a,b])
print(output)
Reply


Messages In This Thread
Do something with all possible combinations of a list - by 3Pinter - Sep-11-2019, 06:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Finding combinations of list of items (30 or so) LynnS 1 1,621 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  How can I find all combinations with a regular expression? AlekseyPython 0 2,247 Jun-23-2021, 04:48 PM
Last Post: AlekseyPython
  All possible combinations CODEP 2 2,669 Dec-01-2020, 06:10 PM
Last Post: deanhystad
  Triplet Combinations of All Values quest 2 2,965 Nov-05-2020, 09:22 AM
Last Post: quest
  All possible combinations of multiplications Shreya10o 0 2,210 May-23-2020, 07:45 AM
Last Post: Shreya10o
  counting items in a list of number combinations Dixon 2 2,819 Feb-19-2020, 07:06 PM
Last Post: Dixon
  Python program that list all possible football outcome combinations lukorir 5 11,461 Oct-17-2019, 04:05 AM
Last Post: steve_shambles
  list of string combinations Skaperen 8 4,866 May-22-2019, 01:18 PM
Last Post: Skaperen
  Python to iterate a number of possible combinations teflon 4 6,154 Apr-24-2019, 03:00 AM
Last Post: scidam
  Distances between all combinations in datatset amyd 6 5,602 Dec-13-2018, 01:23 PM
Last Post: amyd

Forum Jump:

User Panel Messages

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