combinations

How to get all possible combinations of three lists

How to get all possible combinations of three lists Question: I have three lists: list_a=[1,2] list_b=[3,4] list_c=[5,6] Now i’m looking for a solution in python by using a loop where a new list iterates through all possible combinations of these three lists (the order is not important): new_list = list_a # -> [1,2] new_list = …

Total answers: 1

Create a data frame containin all possible permutations/combination given a string specifying the number of repetitions

Create a data frame containin all possible permutations/combination given a string specifying the number of repetitions Question: I would like to create a data frame that contains by row the 24^ combinations for all the letters of the alphabet, i.e. starting with: begin = pd.DataFrame({ "combi":["AAA","AAB","AAC","AAD"]}) and ending with: end = pd.DataFrame({ "combi":["ZZW","ZZX","ZZY","ZZZ"]}) this is …

Total answers: 1

Combinations of words and digits with specific order

Combinations of words and digits with specific order Question: I need all possible combinations of upper words and digits in this format digit-word-word-word . I tried this code : upper_a = [‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’, ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, ‘V’, ‘W’, ‘X’, …

Total answers: 2

Python: Extract all possible mutually exclusive pairs?

Python: Extract all possible mutually exclusive pairs? Question: I have an assignment problem where I have N participants and need to find all possible 2-person assignments where every participant is assigned to exactly one pair. When I use list(combinations(range(100), 2)) I get a "flat" list of about 4000 items, each a pair in the form …

Total answers: 2

Is there a more elegant way of getting permutations with replacement in python?

Is there a more elegant way of getting permutations with replacement in python? Question: I currently want all permutations of a set of elements with replacement. Example: elements = [‘a’, ‘b’] permutations with replacement = [(‘a’, ‘a’, ‘a’), (‘a’, ‘a’, ‘b’), (‘a’, ‘b’, ‘a’), (‘a’, ‘b’, ‘b’), (‘b’, ‘a’, ‘a’), (‘b’, ‘a’, ‘b’), (‘b’, ‘b’, …

Total answers: 1

Is there a way to generate combinations, one at a time?

Is there a way to generate combinations, one at a time? Question: I can generate combinations from a list of numbers using itertools.combinations, such as the following: from itertools import combinations l = [1, 2, 3, 4, 5] for i in combinations(l,2): print(list(i)) This generates the following: [1, 2] [1, 3] [1, 4] [1, 5] …

Total answers: 1

How to loop from a dataframe to another one to count occurence of certain words?

How to loop from a dataframe to another one to count occurence of certain words? Question: enter image description here I have two dataframes, df1 contains a column with all possible combinations and df2 contains a column with the actual combinations. I want to make a second column within df1 that loops through df2 and …

Total answers: 2

Remove all combination of set at the end of string REGEX

Remove all combination of set at the end of string REGEX Question: I want to write a REGEX that removes all combination of a group of characters from the end of strings. For instance removes "k", "t", "a", "u" and all of their combinations from the end of the string: Input: ["Rajakatu","Lapinlahdenktau","Nurmenkaut","Linnakoskenkuat"] Output: ["Raja","Lapinlahden","Nurmen","Linnakosken"] Asked …

Total answers: 2

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