Skip to main content
Engineering LibreTexts

4.26: Creating the Board Data Structure- Step 1 – Get All Possible Icons

  • Page ID
  • def getRandomizedBoard():
        # Get a list of every possible shape in every possible color.
        icons = []
        for color in ALLCOLORS:
            for shape in ALLSHAPES:
                icons.append( (shape, color) )

    The board data structure is just a list of lists of tuples, where each tuple has a two values: one for the icon’s shape and one for the icon’s color. But creating this data structure is a little complicated. We need to be sure to have exactly as many icons for the number of boxes on the board and also be sure there are two and only two icons of each type.

    The first step to do this is to create a list with every possible combination of shape and color. Recall that we have a list of each color and shape in ALLCOLORS and ALLSHAPES, so nested for loops on lines 4 [135] and 5 [136] will go through every possible shape for every possible color. These are each added to the list in the icons variable on line 6 [137].

    • Was this article helpful?