Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Permutation help.
#1
What I have is a list of lists. Something like this:
[[1][4][2][3, 6][4][1]]
what I want back is something like:
[1][4][2][3][4][1], [1][4][2][6][4][1]
or even:
['142341', '142641']
How can I accomplish this please? The only ideas I have seem very convoluted.

Thanks :D
Reply
#2
itertools:

>>> data = [[1], [4], [2], [3, 6], [4], [1]]
>>> list(itertools.product(*data))
[(1, 4, 2, 3, 4, 1), (1, 4, 2, 6, 4, 1)] 
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question How to print each possible permutation in a dictionary that has arrays as values? noahverner1995 2 1,695 Dec-27-2021, 03:43 AM
Last Post: noahverner1995
  Even/Odd permutation braankoo 9 11,499 Jan-10-2021, 01:19 AM
Last Post: Larz60+
  memory error using permutation list of 11 elements kikidog 1 3,844 Sep-10-2019, 08:22 PM
Last Post: ichabod801
  how to get all the possible permutation and combination of a sentence in python sodmzs 1 4,121 Jun-13-2019, 07:02 AM
Last Post: perfringo
  Calling list() on permutation trevorkavanaugh 2 2,350 Mar-01-2019, 06:00 AM
Last Post: trevorkavanaugh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020