Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Itertools Help Please
#1
I tried reading the documentation but it's a little overwhelming.
I have a list of strings. The length of the list and the length of the strings can change in unpredictable ways.
I want to write simple function that will work every time.

Suppose I have a list like this...
['ACF', 'BGH', 'JKLM', 'QWE'] 
What I want to do is generate all possible combinations but each "Digit" is only allowed to be from its own item in the list.
Sorry, I don't know how to word what I mean.

Example:

ABJQ CBJQ FBJQ AGJQ CGJQ FGJQ AHJQ CHJQ FHJQ ABKQ CBKQ.....etc etc

I suspect itertools has a way to do this but there's too many options and I can't find it.
Thanks.
Edit: Never mind. Took about 30 minutes on YouTube but I found out itertools.product will probably work. Just need to figure out how to deal with the fact the list can vary in length now. :D
Reply


Messages In This Thread
Itertools Help Please - by jarrod0987 - Apr-01-2018, 11:30 PM
RE: Itertools Help Please - by scidam - Apr-01-2018, 11:36 PM
RE: Itertools Help Please - by jarrod0987 - Apr-01-2018, 11:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  itertools and amazing speed Pedroski55 8 2,144 Nov-11-2022, 01:20 PM
Last Post: Gribouillis
  What happens to a <itertools.permutations object at 0x7fe3cc66af68> after it is read? Pedroski55 3 2,474 Nov-29-2020, 08:35 AM
Last Post: DeaD_EyE
  Making lists using itertools and eliminating duplicates. mike3891 2 2,283 Oct-26-2020, 05:39 PM
Last Post: bowlofred
  Python3 itertools.groupby printing the key august 1 2,125 Aug-17-2020, 05:46 AM
Last Post: bowlofred
  Generate Cartesian Products with Itertools Incrementally CoderMan 2 1,881 Jun-04-2020, 04:51 PM
Last Post: CoderMan
  itertools.zip_shortest() fo unequal iterators Skaperen 10 6,924 Dec-27-2019, 12:17 AM
Last Post: Skaperen
  can itertools compact a list removing all of some value? Skaperen 6 3,271 Sep-02-2019, 03:19 AM
Last Post: Skaperen
  Help with itertools jarrod0987 1 1,846 Jun-10-2019, 02:41 AM
Last Post: Larz60+
  ImportError: No module named jaraco.itertools in Python manhnt 0 3,020 Nov-08-2018, 11:41 AM
Last Post: manhnt
  Need help with itertools.islice() Charles1 2 2,874 Sep-19-2018, 10:32 AM
Last Post: Charles1

Forum Jump:

User Panel Messages

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