Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
2 answers
124 views

Eliminating Some Combinations From a List of Lists in Python

The code below gives all possible combinations of 6 numbers from 1 to 52. It gives these combinations in a list of lists. However I want to eliminate some of these combinations. The combinations I ...
Thando 's user avatar
2 votes
3 answers
216 views

How to get all unique assignments between two lists

I have two lists that can each contain duplicate values but any value can only appear in one (or none) of the two lists. A = [0,1] B = [2,3] and i want to get all unique mappings between these two ...
J.N.'s user avatar
  • 341
1 vote
2 answers
131 views

Place N unique elements into all possible K groups with monotonicity maintaining

Can anyone suggest a quick and efficient solution for splitting an array of N elements into K groups with monotonicity maintaining? For example: mas = [1, 2, 3, 4, 5] K = 3 Expected output: [1], [2], ...
Alex Lis's user avatar
1 vote
2 answers
614 views

Python More efficient permutation

I have a string that consists of x amount of the letter 'r' and y amount of 'u'. And my goal is two print all possible combinations of that same amount of x,y with different orders. This my example of ...
Dan7nm's user avatar
  • 51
2 votes
1 answer
110 views

How to find a list of all possible decompositions of a list into chunks of size bigger than 2

For a given N, I have a list of all numbers from 0 to N-1 A = list(range(0,N)); and I want to find a list of all possible decompositions into lists of sizes two or higher, without repetitions. For ...
NicoPranzo's user avatar
-2 votes
3 answers
357 views

Repeat a sequence of a list [closed]

Problem Given the following list: l=[1,2,3,4,5,6] I want to repeat the n first elements of the list r times, and after that, do the same for the next n elements of the list, and so on... For example, ...
Optical_flow_lover's user avatar
-1 votes
2 answers
65 views

Obtaining recursively permutations of a single list

I am working in Python and I would like to obtain some kind of 'permutations' of a single list. I will make my best to explain the problem, but let me know if there is any doubt. Imagine we have a ...
Theo Deep's user avatar
  • 766
1 vote
1 answer
225 views

Generate in Python combinations of n elements of a list taken from r in r and check for constraint satisfaction

Suppose we have the following list representing candidate IDs: candidates = list(range(1,37)) I would like to generate, in an affordable computational time, a list containing 6 list of tuples, that ...
0xGolovkin's user avatar
0 votes
2 answers
167 views

How do I use python recursion in this scenario?

"Write a recursive function called anagram(s) that returns a list of all the possible anagrams of the string, s." Can I get some guidance on how to tackle this question? I am new to ...
Luu Luu's user avatar
0 votes
2 answers
81 views

Adding elements of combinations of vector in a list in R

I am pretty new in R and so what I am trying to do is that I have been given a vector of positive integers like index <- 1:3 and I want to use this vector to find all the possible combinations of ...
Theskywalker15's user avatar
0 votes
1 answer
334 views

How can I calculate the sums of all possible combinations of elements of a set? [Python]

For example, I have the list L = [1,2,4]. For the sake of comprehension, I want to list all the combinations for two pulls with a put back (the order does not matter): [1,1] [1,2] [2,2] [1,4] [2,4] ...
Physics's user avatar
  • 113
1 vote
1 answer
326 views

How to convert a dictionary of lists into a list of unique dictionaries according to a particular combinatorial logic?

I have a dictionary of lists like so: var dictOfLists = new Dictionary<string, List<string>> { ["foo"] = new List<string>{ "a", "b", "c" },...
GladstoneKeep's user avatar
2 votes
4 answers
1k views

Is there a fast algorithm for generating all partitions of a set into subsets of size 2 (and one subset of size 1)?

As stated in the title, I'm trying to generate all partitions of a set of size n where all the subsets have size 2, and if n is uneven, there is ne singleton set. I very slightly modified some SO code ...
E. Staikov's user avatar
1 vote
1 answer
111 views

C stack overflow HASKELL , while handling strings

I want to find all the possible partitions of a string into a list of non-empty strings. For example if i give as input "sun", i want to create this output : [["s","u",&...
gregni's user avatar
  • 417
0 votes
1 answer
454 views

Counting all possible combinations in a given list of list

I have a list of list as list_1 =[[A,B,C,D],[A,D],[B,C,D]]. I would like to have an output such as: So as shown above I expect the Count of all possible combinations that are present in the list of ...
Krish Rewanth's user avatar
0 votes
5 answers
3k views

Convert a map of lists into a list of maps

I have a map of lists like: Map("a" -> [1,2,3], "b" -> [4,5,6], "c" -> [7]) I need to produce: [ Map("a" -> 1, "b" -> 4, "c" ...
Harry R's user avatar
1 vote
2 answers
315 views

Get all possible combinations between two lists, including multiple connections

With import itertools l1 = [1,2,3,4] l2 = [1,2,3,4] x = itertools.product(l1, l2) print(list(x)) I get the 16 possible individual combinations of the lists l1 and l2, [(1,1), (1,2), ... ] etc. Is ...
P. H. Allus's user avatar
0 votes
0 answers
149 views

Implementing permutation given a list of all possible combinations

I am attempting to implement a version of permutation using a function I already wrote i'm calling pair-divide which gives me all the possible pair combinations of a list. For example (list 9 10 11) ...
jackr's user avatar
  • 11
0 votes
2 answers
250 views

How to get all possible combinations of dividing a list of length n into m sublists

In my specific case I would like to get all possible combinations of dividing a list of length 20 into 4 sublists. The sublists may have any length from 1 to 17. As a result I would like to have a ...
volfi's user avatar
  • 467
2 votes
1 answer
801 views

All combinations of elements of N lists in Haskell [duplicate]

In order to combine 2 lists the following code could be used. [(x,y) | x <- [1, 2, 3], y <- [4, 5, 6]] Or (,) <$> [1,2,3] <*> [4,5,6] Which produce [(1,4),(1,5),(1,6),(2,4),(2,5),(2,...
user avatar
1 vote
1 answer
186 views

Zip_longest Plus: Iterating through lists of Different Lengths [duplicate]

I have been going through the questions on iteration through lists of unequal lengths, like this one, but I have been unable to find one which addresses my exact requirements. I have two lists of ...
john_mon's user avatar
  • 517
2 votes
2 answers
522 views

Permutation of list of lists of booleans in Racket

I'd like to create a function that: given a natural number, returns a list of lists with all the possible values for n propositional variables. e.g, given n = 3, it should return: (list (list #...
Morena's user avatar
  • 31
0 votes
0 answers
43 views

Finding all the lists of lenght n with only 1s and 0 in Python [duplicate]

I'm stuck on a question that should be an easy one but I can't possibly solve. Given an integer n, I need to find all the possible combinations of lists that contain only 1s and 0s. For example , with ...
Francesco's user avatar
2 votes
1 answer
160 views

Invertible combination generator for ordered lists

I have code where given a list of ordered integers I generate several new lists, and I need to be able to map these lists one-to-one with the integers from 1 to N choose k (or 0 to (N choose k)-1) in ...
mkeegan's user avatar
  • 23
0 votes
3 answers
306 views

How to generate all permutations of the flattened list of lists?

How to generate all permutations of the flattened list of lists in Python, ... such that the order in the lists is maintained? Example; input; [[1,2], [3]] output; [1,2,3] [1,3,2] [3,1,2] 1 is ...
owillebo's user avatar
  • 655
0 votes
2 answers
381 views

Distribute values based on sum and list of provided values

I need to generate list of values from provided that satisfy this requirements: Sum of all generated values should be equal of total, only providedValues should be used to get the sum, providedValues ...
ivanesi's user avatar
  • 1,663
-2 votes
4 answers
886 views

How to create all possible combinations of these two lists?

I'd like to take from these two lists to create a list of all combinations, where each combination is also a list. E.g. Given two lists: [1,2,3] and [True, False] Combinations: [(1, False), (2, ...
doctopus's user avatar
  • 5,637
0 votes
1 answer
108 views

Most efficient way of producing constrained pairs of combinations out of a list in Python

I need to iterate through pairs (a, b) and (c, d) of combinations of length 2, out of a list l of items, with the following constraints: no repetitions in pairs: if (a, b) already appeared, then (b, ...
kr1zz's user avatar
  • 126
1 vote
3 answers
183 views

Combinations of elements from two lists

I have two lists: list1 = ["a", "b", "c", "d"] list2 = [1, 2, 3] I want to take 3 elements from list1 and 2 elements from list2 to combine like the following (a total of 12 combinations): [a b c 1 ...
Binh Thien's user avatar
0 votes
3 answers
182 views

Python: Get n possible minimum sets of m values from the list

There is given a dictionary with few points with their distance where key - name of the point, and value - it's distance, i.e. points_dict = {"a": 18, "b": 7, "c": 15, "d": 22, "e": 33, "f": 5} The ...
Назарій Кушнір's user avatar
0 votes
1 answer
36 views

All possible combinations combining n lists with at least on elem of each list

with an input of n lists which may contain n elements each. i want to find all combinations which have at least one element of each input list. example with 2 input lists of length 2 input 1: {1,2} ...
dasAnderl ausMinga's user avatar
-1 votes
2 answers
247 views

Create all possible char combinations from an unknown amount of lists in python [duplicate]

I want to create all possible character combinations from lists. The first char needs to be from the first array, the second char from the second array, etc. If I have the following lists: char1 = [...
user31751's user avatar
3 votes
3 answers
4k views

Permutation implementation in Haskell

I was trying to implement permutation of a list in Haskell. The idea for permutations is this: The base cases are when list length is 0 and 1 which is the list itself, and when size is 2, the ...
Be Wake Pandey's user avatar
1 vote
3 answers
282 views

Algorithm to list all pairings of two sets fitting criteria

I have 2 finite sets: Set A: {A, B, C, D, ...} Set B: {1, 2, 3, 4, ...} They could be of the same or different lengths. I'm trying to pair them up so that each element in Set A is paired to exactly ...
Evan Belcher's user avatar
2 votes
2 answers
992 views

Cartesian Product of Sets where No Elements are Identical under Permutations in Python

I have some sets I would like to take the Cartesian product of, which is working well. However, I want to remove all elements of this new set which are identical under a permutation of the elements. ...
QtizedQ's user avatar
  • 310
-2 votes
1 answer
792 views

Permutations of a list with constraints python

I am desperately trying to get all the permutations of a list while enforcing position assignment constraints. I have a list [1,2,3,4,5,6] (6 is just an example, I would like to find something that ...
Jkev's user avatar
  • 197
-2 votes
2 answers
99 views

Generate all possible permutation functions

I am interested in finding the permutations p:S->S within a set S={1, 2, ..., n}. In particular, all the functions that either permute i and j: p(i)=j and p(j)=i; or leave them unchanged p(i)=i or p(j)...
rmas's user avatar
  • 29
29 votes
2 answers
30k views

Get all pairwise combinations from a list

For example, if the input list is [1, 2, 3, 4] I want the output to be [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)] If possible, I would like a solution which is better than the brute force ...
Utsav Vakil's user avatar
4 votes
5 answers
2k views

Random access over all pair-wise combinations of large list in Python

Background: I have a list of 44906 items: large = [1, 60, 17, ...]. I also have a personal computer with limited memory (8GB), running Ubuntu 14.04.4 LTS. The Goal: I need to find all the pair-wise ...
jackzellweger's user avatar
3 votes
5 answers
1k views

N choose N/2 sublists of a list

Is there an efficient way in Python to get all partitions of a list of size n into two subsets of size n/2? I want to get some iterative construct such that each iteration provides two non-overlapping ...
user3501476's user avatar
  • 1,153
2 votes
2 answers
783 views

Permutations and indexes, python

I create a list of all permutations of lets say 0,1,2 perm = list(itertools.permutations([0,1,2])) This is used for accessing indexes in another list in that specific order. Every time a index is ...
NicolaiF's user avatar
  • 1,333
1 vote
1 answer
157 views

Recursively generate Compositions from an ordered list

Given an ordered list of 'n' elements, I want to slice the list to generate every distinct permutation of sublists once only, whilst maintaining the order of the original list - i.e. generate every ...
Dave's user avatar
  • 525
1 vote
1 answer
469 views

Combinations with repetition in prolog that satisfy certain criteria

I'm trying to make a prolog program that generates all combinations (with repetition) of n elements from a list of m elements whose sum is between two given number A and B. I managed to make the ...
Laura Aria's user avatar
1 vote
3 answers
76 views

Creating lists from data file

I have a pre-defined list that gives data in the form of (min, max, increment). for example: [[0.0 1.0 0.1 #mass 1.0 5.0 1.0 #velocity 45.0 47.0 1.0 #angle in degrees 0.05 0.07 0.1 #drag coeff....
ibanez221's user avatar
  • 145
-1 votes
3 answers
71 views

Functional form of all tuples extracted from a list

I have a list of six elements {1,2,3,4,5,6} I want to describe the list of all 3-tuples (with repetition) in functional form such that f[1]=<1,1,1> f[2]=<1,1,2> ... f[720]=<6,6,6>...
user16153's user avatar
54 votes
2 answers
11k views

What does this list permutations implementation in Haskell exactly do?

I am studying the code in the Data.List module and can't exactly wrap my head around this implementation of permutations: permutations :: [a] -> [[a]] permutations xs0 = xs0 : ...
tonlika's user avatar
  • 737
21 votes
2 answers
2k views

How to get all mappings between two lists?

We have two lists, A and B: A = ['a','b','c'] B = [1, 2] Is there a pythonic way to build the set of all maps between A and B containing 2^n (here 2^3=8)? That is: [(a,1), (b,1), (c,1)] [(a,1), (b,...
Jean-Pat's user avatar
  • 1,869
4 votes
2 answers
4k views

Using combinatorics in Python to list 4-digit passcodes

I came across this interesting article about why using 3 unique numbers for a 4-digit passcode is the most secure: (LINK) The math involved is pretty straightforward - if you have to guess a phone's ...
user2957365's user avatar
0 votes
1 answer
61 views

Storing First X Items of a Large List (Python)

Let's say we generate a large list of lists in Python using the combinations iterable, and you wanted to retrieve a list with certain properties. If the list of lists is sufficiently large, merely ...
Noob Coder's user avatar
5 votes
3 answers
1k views

Generalize list combinations to N lists

Generating the combination of a known number of lists is quite simple in Scala. You can either use a for-comprehension: for { elem1 <- list1 elem2 <- list2 } yield List(elem1, elem2) Or ...
maasg's user avatar
  • 37.4k