python-itertools Questions
1
Is there a function to calculate the number of permutations with repetition in Python? I know with itertools I can generate them but I want only a faster way to do the calculation and avoid calcula...
Zenaidazenana asked 13/9, 2018 at 9:11
3
Solved
There is an existing thread about this
Zipping unequal lists in python in to a list which does not drop any element from longer list being zipped
But it's not quite I'm after.
Instead of returning ...
Buddhi asked 25/4, 2019 at 10:9
3
I would like to save the state of itertools.product() after my program quits. Is it possible to do this with pickling? What I am planning to do is to generate permutations and if the process is int...
Solemnize asked 9/11, 2014 at 18:27
5
Solved
I'm currently using something like
>> import itertools
>> ABC = [a, b, c]
>> abc = itertools.cycle( ABC )
>> next( abc )
a
>> next( abc )
b
>> next( abc )
c
...
Trujillo asked 18/6, 2017 at 5:4
4
Solved
Given a list of pairs xys, the Python idiom to unzip it into two lists is:
xs, ys = zip(*xys)
If xys is an iterator, how can I unzip it into two iterators, without storing everything in memory?
...
Wizardly asked 12/6, 2015 at 14:3
1
I am evaluating successive terms of the look and say sequence (more about it here: https://en.wikipedia.org/wiki/Look-and-say_sequence).
I used two approaches and timed them both. In the first app...
Pastose asked 4/7, 2018 at 23:13
3
I am searching for a middle ground between Python's zip and zip_longest functions (from the itertools module), that exhausts all given iterators, but does not fill in anything. So, for example, i...
Suzetta asked 27/6, 2016 at 12:56
6
Solved
Say I have a string list:
li = ['a', 'b', 'c']
I would like to construct a new list such that each entry of the new list is a concatenation of a selection of 3 entries in the original list. Note...
Salema asked 31/8, 2017 at 21:38
3
I'm trying to implement my own version of itertools.compress, the problem is that i stumbled upon the return type. I mean both of these functions return an iterator, but i think the second one is n...
Provisory asked 10/8, 2017 at 18:1
3
Solved
I have N positions, and each position can be either 0 or 1. I have fixed number of 1s, and I want to permutate these fixed number of 1s in these N positions.
from itertools import permutations
p =...
Daye asked 6/5, 2017 at 5:10
15
Solved
I haven't been able to find an understandable explanation of how to actually use Python's itertools.groupby() function. What I'm trying to do is this:
Take a list - in this case, the children of a...
Bluepencil asked 3/8, 2008 at 18:27
3
Solved
Python's Itertools has what is called starmap. Given a collection of collections and a function, it applies the function to each collection strictly inside the collection, using the elements of sai...
Lavin asked 12/1, 2023 at 9:5
3
Solved
I'm using itertools.combinations() as follows:
import itertools
import numpy as np
L = [1,2,3,4,5]
N = 3
output = np.array([a for a in itertools.combinations(L,N)]).T
Which yields me the outpu...
Howerton asked 9/2, 2017 at 14:0
1
Solved
Im trying to accomplish a Vectoriced Numpy version of itertools.combinations, that I futher can decorate with @jit (Numba) - To make it even faster. (I am not sure if this even can be done)
The dat...
Jaquelinejaquelyn asked 14/12, 2022 at 9:31
7
I am writing a code to take an enormous textfile (several GB) N lines at a time, process that batch, and move onto the next N lines until I have completed the entire file. (I don't care if the last...
Vestal asked 13/6, 2011 at 20:20
3
Solved
The result created by Python's itertools.combinations() is the combinations of numbers. For example:
a = [7, 5, 5, 4]
b = list(itertools.combinations(a, 2))
# b = [(7, 5), (7, 5), (7, 4), (5, 5),...
Montemontefiascone asked 26/11, 2014 at 13:55
3
Solved
I though this would be straightforward, unfortunately, it is not.
I am trying to build a function to take an iterable of dictionaries (i.e., a list of unique dictionaries) and return a list of list...
Toul asked 24/12, 2018 at 17:32
20
Solved
itertools.permutations generates where its elements are treated as unique based on their position, not on their value. So basically I want to avoid duplicates like this:
>>> list(itertool...
Matti asked 8/6, 2011 at 19:51
6
Solved
I am trying to use itertools.permutations() to return all the permutations of the string and return only the ones which are members of a set of words.
import itertools
def permutations_in_dict(st...
Blintze asked 1/7, 2017 at 6:17
5
Solved
I need a python functional (a function that creates functions), which creates all cyclic permutation operators for a list of length N.
For a python list a (e.g. a = [1, 2, 3, 4,5,6], N= 6), one c...
Thorazine asked 16/5, 2019 at 14:46
4
Solved
I am using itertools to group by a dictionary key using the below:
host_data = []
for k,v in itertools.groupby(temp_data, key=lambda x:x['device_id'])
d = {}
for dct in v:
d.update(dct)
host_d...
Odey asked 27/6, 2018 at 10:13
3
Solved
BackgroundI have a complex nested JSON object, which I am trying to unpack into a pandas df in a very specific way.
JSON Objectthis is an extract, containing randomized data of the JSON object, whi...
Wood asked 13/2, 2022 at 21:7
4
Say we wish to process an iterator and want to handle it by chunks.
The logic per chunk depends on previously-calculated chunks, so groupby() does not help.
Our friend in this case is itertools.t...
Tabular asked 3/6, 2015 at 9:11
4
I need code that takes a list (up to n=31) and returns all possible subsets of n=3 without any two elements repeating in the same subset twice (think of people who are teaming up in groups of 3 wit...
Seeder asked 15/11, 2011 at 8:20
5
Solved
From this post I learned that you can concatenate tuples with sum():
>>> tuples = (('hello',), ('these', 'are'), ('my', 'tuples!'))
>>> sum(tuples, ())
('hello', 'these', 'are', '...
Petrarch asked 6/2, 2017 at 2:38
1 Next >
© 2022 - 2025 — McMap. All rights reserved.