combinations

Find all combinations that add up to given number python with list of lists

Find all combinations that add up to given number python with list of lists Question: I’ve seen plenty of threads on how to find all combinations that add up to a number with one list, but wanted to know how to expand this such that you can only pick one number at a time, from …

Total answers: 3

Python to list all the combinations of any-3-elements in a list

Python to list all the combinations of any-3-elements in a list Question: Finding a way to list all the combinations of any-3-elements in a list: Here is what I tried: import itertools the_list = ["Alpha","Beta","Gamma","Delta","Epsilon","Zeta"] list_of_trios = [(the_list[p1], the_list[p2], the_list[p3]) for p1 in range(len(the_list)) for p2 in range(p1+1,len(the_list)) for p3 in range(p1+2,len(the_list))] tem_list = [] …

Total answers: 1

Generate all possible combinations of characters, of every length, from an array using Python

Generate all possible combinations of characters, of every length, from an array using Python Question: I want to generate all possible combinations of letters from array ["a", "b", "c"] I’ve seen programs that should have generated all combinations but I got [(‘a’, ‘b’), (‘a’, ‘c’), (‘b’, ‘c’)] which is wrong because its missing (‘b’, ‘a’), …

Total answers: 2

Finding what is most commonly purchased with a specific product – PANDAS

Finding what is most commonly purchased with a specific product – PANDAS Question: I am trying to find the most common products purchased with the product ‘SWE’ but am currently stuck. I have the variables ‘product’ and ‘sales_invoice’ So far I have this code: df_pairs = df_pairs = df.groupby(df[‘product’].str.contains(‘SWE’))[‘sales_invoice’] print(df_pairs.head()) it results in a list …

Total answers: 1

Discard some sets in list with all possible combinations

Discard some sets in list with all possible combinations Question: Let’s say I have 5 points in graph, v = [0,1,2,3,4]. The list with all possible combinations would look like this: [(), (0,), (1,), (2,), (3,), (4,), (0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), …

Total answers: 1

How to code a factorial matrix combination in Python

How to code a factorial matrix combination in Python Question: Consider the following input matrix (- are arbitrary values): A B C D E F A – – – – – – B – – – – – – C – – – – – – D – – – – – – E – …

Total answers: 1

Get all combinations of a binary string with bit flips at specific indices (Python)

Get all combinations of a binary string with bit flips at specific indices (Python) Question: I have a binary string. I have a list of bit indices to flip. How can I generate all possible combinations of binary strings with flips at those specific indices? The output list should contain 2^n unique elements where n …

Total answers: 3

Combination between two lists using cartesian product with a small twist

Combination between two lists using cartesian product with a small twist Question: I am trying to do an algorithm where I find all the possible combination between two lists but I am not sure how do we call this type of combination in math: Input: List 1 : [a,b,c,d] and List 2 : [1,2,3,4] Desired …

Total answers: 2