-3

Given the following dictionaries:

dict_first_attempt = {'Offense': ['Jack','Jill','Tim'], 
'Defense':['Robert','Kevin','Sam']}
dict_second_attempt = {'Offense': ['Jack','McKayla','Heather'],
'Defense':['Chris','Tim','Julia']}

From this dictionaries, my focus is just the offense, so if I just wanted the list of those, I would do this:


first = dict_first_attempt['Offense']
second = dict_second_attempt['Offense']

For each of those lists, I am trying to create a code that can do the following:

  1. Tell me all the possible combinations of first attempt offense and second attempt offense.
  2. Outputs it in a list, with lists of the combinations.
  3. The first element within the list has to be from the first attempt offense, and the second element has to be from the second attempt offense.

An example of the type of output I want is:

[['Jack','Jack'],['Jack','McKayla'],['Jack','Heather'],
['Jill','Jack'],['Jill','McKayla'],['Jill','Heather'],
['Tim','Jack'],['Tim','McKayla'],['Tim','Heather']]
PKrange
  • 111
  • 1
  • 7
  • 2
    Welcome to SO! What exactly have you tried so far? We're much more here to help with specific questions of the form "I tried X, but it did not do what I expect and instead resulted in an error!" accompanied by a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – ti7 Nov 19 '22 at 21:48

1 Answers1

1
import itertools
list(itertools.product(first, second))
amirhm
  • 1,239
  • 9
  • 12
  • As a general rule, if the answer is "use a builtin or standard library function exactly as it's documentation suggests", the question is a duplicate. The recommended action in this case is to find the duplicate and flag this question, since it is more valuable to the community to have all relevant information in a single place. Such questions usually get downvoted and closed quite quickly and later deleted. – Pranav Hosangadi Nov 19 '22 at 23:39