python-itertools

How to get the correct answers from a permutation / combination problem?

How to get the correct answers from a permutation / combination problem? Question: Given the following input, I would like to implement a function, that calculates the amount of possible correct answers, without calculating each answer for computational reasons. I hope the function to look something like this: from itertools import combinations_with_replacement from itertools import …

Total answers: 1

Sequential chaining of itertools operators

Sequential chaining of itertools operators Question: I’m looking for a nice way to sequentially combine two itertools operators. As an example, suppose we want to select numbers from a generator sequence less than a threshold, after having gotten past that threshold. For a threshold of 12000, these would correspond to it.takewhile(lambda x: x<12000) and it.takewhile(lambda …

Total answers: 1

All possible integer array of fixed length for a given norm?

All possible integer array of fixed length for a given norm? Question: Given d and t, positive integers, i would like to generate all possible 1D arrays of length d such that coordinates are positive integers and their sum is less or equal to t. For example, for d=2, and t=2, such possibilities are : …

Total answers: 1

How to group items in list in python if the value change?

How to group items in list in python if the value change? Question: Suppose I have a list msg_type =["sent-message", "received-message", "received-message", "sent-message", "received-message", "sent-message", "received-message", "received-message", "sent-message", "sent-message", "received-message", "sent-message", "sent-message", "received-message", "sent-message", "sent-message", "received-message", "sent-message", "received-message", "received-message", "sent-message", "sent-message", "received-message", "sent-message", "received-message", "sent-message", "received-message" ] How would I be able to group this …

Total answers: 2

Two lists – find all permutations – even multiple to one – Round 2

Two lists – find all permutations – even multiple to one – Round 2 Question: I asked this question previously, but things changed so new question is in order. I have two lists and I need to find all permutations. The kicker is that multiple "number" items (as per example below) can be assigned. No …

Total answers: 1

Pandas itertuples – fill in a matrix with a value based on an event

Pandas itertuples – fill in a matrix with a value based on an event Question: I am trying to create a matrix in which I fill in the date of the first occurence of an event per row after the specified stamp date in the said row. Sample dataframe: id = [1,1,1,1,1,2,2,2,2,3,3,3,3,4,5,6,7,7,7,8,8,8,9,9,9,10,10,10] fact = ["IC", …

Total answers: 1

All combinations from multiple lists with different indices

All combinations from multiple lists with different indices Question: I have N lists of M elements (each list), N < M. I would like to have all the combinations from them with the conditions: each combination has N elements, all indices in combination (from the original list) are unique. Example for 3(N) lists of 4(M) …

Total answers: 4

problem with itertools permutations in combination with english_words_set in a for loop

problem with itertools permutations in combination with english_words_set in a for loop Question: I want to get all possible words with 5,6,7 characters from a random string: word="ualargd" I do the following: A for loop to change the length of my permutations. for i in range(5,len(word)+1): mywords=permutations(word, i) The items created by the permutation get …

Total answers: 1