python - How to make all combinations of the elements in an array? -


I have a list with x lists, each y element. I want to add each element with all the other elements, just once, (a, b = b, a)

Edit: It has been criticized for being very obscure. I describe my function produces random equations and uses genetic techniques, mutates and adds them mutually, selecting for fitness. After several iterations, it gives a list of 12 objects, which are sorted according to the fitness of their 'equation' attributes. Using the 'parallel dragon' module to run this function 8 times, a list containing 8 lists of 12 objects (each has each equation feature) Each is returned Now, within each list, 12 objects are already There are cross breads with each other. I want to cross-breed each object in all other lists with all the other items, but they

Itertools.product is your friend.

About removing duplicates, try with a set of sets.

Now it is a bit clearer what you want:

  import itertools def recombinate (families): "These families are a list of 8 elements, each person has 12 individuals "Fire", for Fire, Iterolus Womens (Families, 2) in Fa: Pair in Iteratiles. Product (Fi, FJ): Product Pair  

Originally, all of the family 2 combinations (produced in parallel) and for each pair of families, the elements Eat all the pairs of.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -