Skip to main content

All Questions

0 votes
1 answer
112 views

Create Permutations and Combinations of List in Python (Efficiently)

I want to create a list that contains every permutation of various combinations of elements satisfying a certain condition. Specifically, I want every list of a given length consisting of mostly zeros ...
EllipticalInitial's user avatar
0 votes
1 answer
75 views

Convert a list of list items to dict

I have list list like this [[], ['1.0', '1.0 (proxy)', '1.1', '1.1 (proxy)', '2.0', '2.0 (proxy)', '3.0', '3.0 (proxy)'], ['1.0', '1.0 (proxy)', '1.1', '1.1 (proxy)', '2.0', '2.0 (proxy)', '3.0', '3.0 ...
Chang Zhao's user avatar
1 vote
1 answer
438 views

Ways of speeding up the itertools.product in python

I'm trying to create a numpy array consisting of all possible asset allocations using itertools.product. The conditions are that allocations for each asset can be in range of zero to 100% and can rise ...
MarginCall's user avatar
0 votes
1 answer
851 views

Get itertools object by index, similar to how you get in list

Are there any quick ways that I can easily derive the index from an itertools.izip object, similar to how you derive from a list? I am trying to compare 2 values, one from a list, the other from the ...
Teh Ki's user avatar
  • 455
1 vote
1 answer
292 views

The first time I use next to get the elements in the iterator, an exception is thrown

There are two .py files test.py # coding=utf-8 from itertools import chain def task(): c = [1, 21, 31, 4, 51, 61, 71] d = ['a1', 'b1', 'c', 'd', 'e1', 'f', 'g1'] e = chain(c, d) ...
Yiming Chen's user avatar
0 votes
3 answers
238 views

How to group dicts (compare dicts) based on all the keys?

I'm writing a python script which parses "n" number of xml's first and creates a dict of dict's with key-value being xml attributes (inside nested dicts). Now, I want to group these nested dicts ...
PeXXeR's user avatar
  • 101
-2 votes
3 answers
1k views

Using zip_longest on unequal lists but repeat the last entry instead of returning None

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 ...
Ben's user avatar
  • 25
1 vote
1 answer
193 views

printing characters before and after takewhile in python

I have a python list in which i need to do takewhile. I am getting output as ['fd', 'dfdf', 'keyword', 'ssd', 'sdsd'] but I need to get ['3=', 'fd', 'dfdf', 'keyword', 'ssd', 'sdsd', ';'] from ...
qwww's user avatar
  • 1,363
0 votes
1 answer
81 views

How can we get range of dates (ex. from Jan 2000 to Dec 2010 ) in the format of 01012000-31122012) using itertools.permutations?

I am basically creating a bruteforcer in python combos=itertools.permutations("i34U^hP-",8) This is where I need to find the regex instead of that given inside the brackets.
Humble's user avatar
  • 21
1 vote
3 answers
1k views

Generate only continuous combinations of a list of numbers [duplicate]

I have a list in python [1, 2, 3, 4, 5, 6]. I want to generate all possible combinations of length 2, 3, 4 and 5. I have used itertools.combinations to generate the combinations but it doesn't ...
Avinash Kadimisetty's user avatar
4 votes
2 answers
1k views

itertools permutations and combinations

I am struggling with using itertools permutations and combinations together. Ultimately, I am trying to create a matrix of possible combinations of Customers across various permutations of machines. ...
mb12's user avatar
  • 41
0 votes
1 answer
427 views

python: calling set over Itertools product object second time clear data [duplicate]

when calling set(c) second time it show empty set, it clear data butit working fine for first time and address of object is also same . >>> import itertools >>> a = ["aaa", "bbb", "...
Kallz's user avatar
  • 3,543
0 votes
0 answers
194 views

Python / regroup several files in list according their sizes with a interval

I would like to group several files in a folder according to their size. However, this size must be within an interval of + -200 bytes. That is, if one file weighs 2698752 Bytes, and another weighs ...
Marshall Cocop's user avatar
1 vote
4 answers
79 views

Joining sublists in two nested in python 2.7

I am sorry for the long post. Please could someone help me with the merging of two nested lists of different lengths? There are countless examples of joining lists "elementwise" on Google and on SO, ...
Paul's user avatar
  • 558
0 votes
1 answer
852 views

How can I concatenate all of the responses from (Python's) iter_tools.product()? [duplicate]

I'm trying generate a list of all possible combinations of characters over a several lengths using Python 2.7. For the sake of example, I'm using a much smaller subset to proof the concept. Below I ...
user3.1415927's user avatar

15 30 50 per page
1
2 3 4 5
8