Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
82 views

Python3.8 cannot import name 'windowed_complete'

Ubuntu 20.04 Python 3.8 Got error ImportError: cannot import name 'windowed_complete' from 'more_itertools' However more_itertools is clearly installed. Is it possible, that Python 3.9 required to ...
Mary N's user avatar
  • 97
1 vote
1 answer
49 views

Find if a set of lists of 2 values are the result of the possible combination of a n-value list

I have used itertools to find all possible 2-element combination (without repetition) from a set of 10 elements to which I have applied some filtering to reduce the 2-element combination based on ...
Marco_sbt's user avatar
  • 327
-1 votes
2 answers
33 views

How to group or batch the list of elements based on indices sublist?

How to group or batch the list of elements based on indices sublist ? Below are the possible instances should be considered. Hope that helps better. 1st Instance : Length of elements == sum of all ...
Learner's user avatar
  • 91
0 votes
1 answer
89 views

(more_)itertools function to group (predicate true/false) tuples with group borders at first item in group

I'm looking for an iterator preferably from itertools or more_itertools that groups my_list such that each group starts at the first even digit that follows after an odd digit (or has no predecessor). ...
koks der drache's user avatar
0 votes
2 answers
161 views

How to generate permutations without repetition

I have a table that looks like below Loc ID filter P1 A ABC1 GHY 55.6 A DFT1 FGH 67.8 B HJH5 GHY 67 C HKL BHY 78 B GTY FGH 60 I want the output as below. Basically, I want the records with the ...
Sai's user avatar
  • 47
1 vote
1 answer
130 views

efficiently listing distinctive permutations that meet 'adjecancy requirements'

I'm trying to store distinctive permutations that meet additional (adjecancy) requirements. Below is a figure to illustrate the problem I am trying to solve. I'm trying to make code that lists all ...
bprsch's user avatar
  • 67
0 votes
1 answer
143 views

Parsing an iterable without listifying each chunk

Suppose I want to achieve a splitting of a Python iterable, without listifying each chunk, similar to itertools.groupby, whose chunks are lazy. But I want to do it on a more sophisticated condition ...
Eric Auld's user avatar
  • 1,244
2 votes
1 answer
903 views

All possible paths from pair combinations

I don't know the proper name for this connected component, yet what I'm looking for is to form paths with all possible combinations of a list of pairs/edges. Given a list: ("A", "B"...
admirabilis's user avatar
  • 2,420
0 votes
1 answer
44 views

Return large list of tuples with replaced dictionary value

In python, I have a list of tuples (lot) with patient data, as shown below: lot = [('490001', 'A-ARM1', '1', '2', "a", "b"), ('490001', 'A-ARM2', '3', '4', "c", &...
Jeromekem's user avatar
1 vote
1 answer
36 views

Replace two characters in tuple element with dictionary value

I have a list of tuples (lot): lot = [('490001', 'A-ARM1'), ('490001', 'A-ARM2'), ('490002', 'B-ARM3')] Subsequently, I loop through every second tuple element and wish to replace every ...
Jeromekem's user avatar
1 vote
4 answers
770 views

In Python, how do I iterate over previous, current and next values of a given list?

I don't even know where to begin to provide an adequate title for this question. Please suggest something better if you can. EDIT: Sorry, I need to clarify my question. I'm looking for something that ...
gskluzacek's user avatar
0 votes
2 answers
91 views

use only part of the data premutation

import itertools alphabet = { "A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6, "G": 7, "H&...
Deswer YouTube's user avatar
5 votes
3 answers
905 views

How to elegantly generate all prefixes of an iterable? (cumulative iterable) [closed]

From an iterable, I'd like to generate an iterable of its prefixes (including the original iterable itself). for prefix in prefixes(range(5)): print(tuple(prefix)) should result in (0,) (0, 1) (0,...
das-g's user avatar
  • 9,964
2 votes
1 answer
92 views

Skipping an Iteration in a Specific List when Iterating through Multiple Lists

This question is somewhat similar to this question, but different in that it entails multiple lists: I have three lists: a = [1, 2, 3, 4, 5, 6, 7] b = ['ball', 'cat', 'dog', 'elephant', 'baboon', '...
john_mon's user avatar
  • 517
0 votes
4 answers
554 views

How to introduce constraints using Python itertools.product()?

The following script generates 4-character permutations of set s and outputs to file: import itertools s = ['1', '2', '3', '4', '!'] l = list(itertools.product(s, repeat=4)) with open('output1.txt',...
SeaDude's user avatar
  • 4,315
0 votes
1 answer
287 views

How to remove string quotations, commas and parenthesis from Python itertools output?

This nice script generates all 4 character permutations of the given set s, and prints them on new lines. import itertools s = ('7', '8', '-') l = itertools.product(s, repeat=4) print(*l, sep='\n') ...
SeaDude's user avatar
  • 4,315
2 votes
3 answers
733 views

Pure python or itertools group a list of dates by days difference between each date

Having a list of dates ordered: [ datetime.date(2006, 8, 15), datetime.date(2006, 9, 12), datetime.date(2007, 8, 10), datetime.date(2021, 4, 6), datetime.date(2021, 4, 16), datetime.date(2021, 4, 19) ....
lsgrep's user avatar
  • 33
0 votes
6 answers
1k views

How to convert a nested list of strings to a one list? [duplicate]

I wanted to convert a nested list of strings into a single list. For example, if there is a list like, fruits = ['apple','orange, ['pineapple','grapes']] I want to convert this to: fruits = ['apple','...
Sarthak Agrawal's user avatar
2 votes
1 answer
8k views

Can't `pip install numpy` with a Python 3.9 venv

I installed Python 3.9, created a venv and tried to install numpy. There was an error with Cython, that was fixed in trunk. So I installed in the venv Cython 3.0a0 and retried: (venv) marco@buzz:~...
Marco Sulla's user avatar
  • 15.9k
0 votes
0 answers
135 views

How to make delimited item in split_at (more_itertools) dynamic

I am using split_at from more_itertools. The reason is that I have a list of 70k records in which Record i [Record 1, Record 2, ...Record n] occurs. I need to split the list at these Record i ...
Jeroen S's user avatar
1 vote
0 answers
84 views

Looking for something like more_itertools random_product, but it must consider each iteration only once

I'm not sure if this is even possible, but basically I'm looking for something like "random_product" from more_itertools but I would like it to consider each iteration only once -- yet still consider ...
jlEe's user avatar
  • 41
3 votes
2 answers
942 views

How can i return the longest continuous occurrence of "True" in Boolean, and replace other True with False?

I am trying to return a boolean which only gives the longest "True" occurrence in the original boolean and replace shorter "True" chunks into "False". Example a=[True, True, False, True , True, True, ...
Jamal 's user avatar
  • 45
3 votes
2 answers
1k views

Python join more_itertools.windowed results

I have a following problem: I am trying to create so-called "digrams", like this: If I have a word foobar, I want to get a list or a generator like: ["fo", "oo", "ob", "ba", "ar"]. The perfect ...
dabljues's user avatar
  • 1,917
10 votes
1 answer
6k views

Invalid syntax in more-itertools when running pytest

I have the following minimal setup.py: import setuptools setuptools.setup( setup_requires=['pytest-runner'], tests_require=['mock', 'pytest'], test_suite='tests', python_requires='&...
dzieciou's user avatar
  • 4,504
0 votes
3 answers
100 views

python shuffle and print string and without reverse string

Let's say I have string, s='AADD'. I have used more_itertools and distinct permutation, which would print out (AADD,ADDA,DDAA,ADAD,DADA,DAAD). My question is, because AADD and DDAA, ADAD and DADA ...
Chameleon_7's user avatar
0 votes
1 answer
2k views

ImportError: cannot import name 'unique_everseen'

I'm trying to import quandl in to spyder (python 3.6) and I get the issues as seen in the title above. Could it be a fault with the more-itertools package, as I have not seen a file within the ...
Andrew's user avatar
  • 245
0 votes
0 answers
106 views

Infinite while loop using conditional statements and peekable iterables?

I'm getting an infinite loop while using more_itertools peekable: import more_itertools as it temp = [line.rstrip('\n') for line in open('sample.txt')] lines = it.peekable(temp) try: while True:...
ahagouel's user avatar