2

Suppose I have a set S=["a", "b"] and a number L=2. What function or standard library tool when passed S and L would yield [["a","a"], ["a","b"], ["b","a"], ["b","b"]] in no particular order?

I'm sure there's a simple answer, I've just been working on my program so long that my brain has been scrambled.

user189728
  • 278
  • 1
  • 10
  • @relisher I was able to find my solution through that question, but calling it a duplicate is quite a stretch. – user189728 Jul 06 '18 at 00:34
  • Not a stretch at all: a string is a sequence of characters, so without duplicates, can adequately represent a set of characters. – Scott Hunter Jul 06 '18 at 00:37
  • 2
    @user189728 while the question may not have been an exact duplicate, the answer to your question (in python!) is the accepted solution – relisher Jul 06 '18 at 21:20
  • @relisher fair enough, I guess I just took it as an attack, which is my fault – user189728 Jul 06 '18 at 21:27

1 Answers1

2

This is itertools.product:

>>> [list(pair) for pair in itertools.product(S, repeat=2)]
[['a', 'a'], ['a', 'b'], ['b', 'a'], ['b', 'b']]
wim
  • 338,267
  • 99
  • 616
  • 750