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
850 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
0 votes
1 answer
349 views

Missing permutation with itertools.permutations()

I was solving the itertools.permutations() code on Hackerrank at https://www.hackerrank.com/challenges/itertools-permutations/problem and I came up with the following very simple code: from itertools ...
gourabix's user avatar
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
0 votes
2 answers
114 views

Create lists with 3 levels, containing every combination of sub list(s) values

I am currently stuck with the following problem (I could not find solution already on here that really fitted this): I have three lists a = [a, b, c], b = [1, 2, 3] and c = [0.1, 0.2, 0.3]. I would ...
Ryan's user avatar
  • 11
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
1 vote
1 answer
420 views

Converting a string obtained from a Pandas dataframe into individual lists per line

test is a pandas dataframe converted to string. strtest = (test.to_string()) print strtest After conversion to string, I have the following output: This is the first test file 98128612.12 This ...
Sam T's user avatar
  • 67
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

15 30 50 per page
1
2 3 4 5
10