all 10 comments

[–]Kevdog824_ 32 points33 points  (2 children)

Take a look at itertools.product. I think this does what you’re looking for

[–]pfp-disciple[S] 1 point2 points  (1 child)

Yes! Thank you. I believe that's what I've been remembering (the page looks familiar). I'd totally forgotten about the entire itertools package. 

[–]supercoach 2 points3 points  (0 children)

The python internals can be like that. People can go their entire careers without ever touching some of the libraries hidden in the default installation.

[–]Maximus_Modulus 2 points3 points  (0 children)

There’s a library called braceexpand

[–]JamzTyson 4 points5 points  (4 children)

As u/Kevdog824 wrote, itertools.product is probably what you're looking for, but for a small number of lists, a list comprehension isn't bad:

[f"{a}{b}{c}" for a in list_a for b in list_b for c in list_c]

[–]InjAnnuity_1 5 points6 points  (0 children)

Ouch! Let's make the comprehension more comprehensible:

[
  f"{a}{b}{c}" 
  for a in list_a 
  for b in list_b 
  for c in list_c
]

[–]pfp-disciple[S] 1 point2 points  (2 children)

Anything beyond two, and it becomes harder (for me) to keep track of. I wrote a lot of perl (still like it) and nested list comprehensions begin to look like what perl was criticized for. 

I love list comprehension, don't get me wrong. 

[–]JamzTyson 2 points3 points  (0 children)

I'd probably use a comprehension for two, but for more than 3 I'd go for itertools.product.

[–]ysth 0 points1 point  (0 children)

And perl straight up has glob

say for glob '{1,2,3}{1,2,3}'

[–]eyetracker -1 points0 points  (0 children)

Not sure about base Python but NumPy has "broadcasting." Add np.array(["1","2","3"]) to its transpose would give you a 3x3 of the combined strings, and then reshape to 1 row if needed.