Skip to main content
4 votes
2 answers
68 views

Is there a way to use itertools with conditions for sets and arbitrary length?

I'm trying to create a list of subsets that add to a particular sum (e.g. 12), but with a limit on the occurrences of some of the terms. The base set to iterate on is {1,2,3,4,5,6,7,8}. I'm trying to ...
wwwm's user avatar
  • 41
3 votes
4 answers
193 views

Cartesian product for both keys and values of a dictionary?

I need to get the Cartesian product of a dictionary {str: Fraction} with itself, but currently need to "loop" through the dict twice, once for the keys and once for the values. The ...
Ameya's user avatar
  • 1,770
2 votes
2 answers
204 views

How can I remove only consecutive duplicate elements from a larger list in Python? [duplicate]

I have a list of elements where I want to remove only consecutive duplicates, not all duplicates. For example: data = [1, 1, 2, 2, 2, 3, 1, 1] I want to get: [1, 2, 3, 1] This is different from using ...
sam's user avatar
  • 45
5 votes
2 answers
146 views

Performance of list.extend slice vs islice

It seems that even when islice would theoretically be better, in practice, it is slower than just using slice. So I am a bit puzzled by the difference in performance between the usage of slice and ...
Mathias Sven's user avatar
1 vote
1 answer
198 views

Create all possible outcomes from numpy matrices that show disjoints and subsets

Let's assume there is an event and within this event there are multiple outcomes that can co-exist. An example would be a tennis game where A plays against B and B serves. A couple of possible ...
HJA24's user avatar
  • 406
2 votes
1 answer
171 views

How to create possible sets of n numbers from m-sized prime number list?

Input: a list of m prime numbers (with possible repetition), and integers n and t. Output: all sets of n numbers, where each set is formed by partitioning the input into n parts, and taking the ...
theozh's user avatar
  • 27k
3 votes
2 answers
101 views

What's the fastest way of skipping tuples with a certain structure in a itertool product?

I have to process a huge number of tuples made by k integers, each ranging from 1 to Max_k. Each Max can be different. I need to skip the tuples where an element has reached is max value, in that case ...
user58327's user avatar
1 vote
0 answers
61 views

How do I use a custom mapping (sort) on my itertools for loop so that I can print specific strings first?

I'm using python itertools specifically to generate combinations of integer strings. I have already created the loop that will loop through the combinations one at a time. I just need someone to help ...
user27394478's user avatar
-1 votes
1 answer
32 views

Tupe video clips list, the other matching durations. Itertools can find triplets that total 90 sec from duration list. Want to print clip names

I can get the triplets with iteration tools in durations list but I want to get matching clips from spots list. Tried to marry two list but dont know how to apply iteration combo on one part of the ...
vjeko sa's user avatar
1 vote
2 answers
49 views

Dealing with `StopIteration` return from a next() call in Python

I'm using the below to skip a group of records when a certain condition is met: if (condition met): ... [next(it) for x in range(19)] Where it is an itertuples object created to speed up ...
Chris's user avatar
  • 1,702
-2 votes
2 answers
69 views

Python itertools product aborting

When running the code below, python aborts and closes the python prompt: >>> import itertools >>> nComb = 2 >>> t = range(nComb) >>> combs = list(itertools.product(...
Memória de Cálculo's user avatar
1 vote
1 answer
86 views

Type hint for itertools.product doesn't know length of elements

I am adding type hints to an old code of mine. However, I find with a "problem" I don't know how to solve. I have a function that looks like: def f(x: tuple[tuple[int, int], ...]): ... ...
Gaussian97's user avatar
2 votes
0 answers
117 views

Efficiently Handling Large Combinations in Polars Without Overloading RAM

I have a list of n values (in my case, n=19), and I want to generate all possible combinations of these values. My goal is to use each combination as a filter for a Polars DataFrame, iterate over the ...
Simon's user avatar
  • 1,187
1 vote
2 answers
274 views

Finding number of differences between strings in Polars

I have a Polars dataframe in which the cells contain a sequence of single digits as a string of characters, and I want to find the number of differences between the elements of the string. For example:...
Josh9999's user avatar
1 vote
1 answer
105 views

Is there an iterator in Python that gives the product but omits permutations of the classes itself?

Assume that I want to assign a color to 5 different balls and have 3 colors r,b and g. I would like to iterate over all these combinations. Preferably I would want to omit combinations that are equal ...
Trailblazer's user avatar

15 30 50 per page
1
2 3 4 5
210