Help to generate a dictionnary

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hjiul

Hello,

I need a little help for a piece of code I am doing. I am convinced it is relatively easy to do and would just involve some nested ‘for loops’ but I cannot visualize how to put it together :

My game has a ship generator.

6 families of ships, lets call them : A, B,C,D,E,F

each boat has 6 different parts, lets call them : 1, 2 ,3 ,4 , 5 , 6

I have a dictionnarie shipParts = {
‘A’ : {
‘1’:‘’,
‘2’:‘’.

‘B’: {
‘1’:‘’,
‘2’:‘’.

The id For each ship is build Related to each part it has in order {1,2,3,4,5,6}.
So it could be ‘AAAAAA’ or ‘ABACCD’ or ‘FFBADC’

You get the idea.

My generator is working fine but now i would love a small script that generate a dictionnary with all possible ids :
AAAAAA
AAAAAB
AAAAAC

Anyone could help me with that ?
I cannot help to think that is should not be very hard but Its making my brain bug since 1h so Here I am humbly asking for a hand :slight_smile:

Thanks

:bust_in_silhouette: Reply From: Inces
var allcombinations = []
        for letter1 in shippart.keys() :
           for letter2 in shippart.keys() :
                for letter3 in shippart.keys() :
                     for letter4 in shippart.keys() :
                            for letter5 in shippart.keys() :
                                  for letter6 in shippart.keys() :
                                        allcombinations.append(letter1+letter2+letter3+letter4+letter5+letter6)

SInce this is 6 dimensional chart with order dependency I am not sure if there is more ellegant way to do this :stuck_out_tongue:
6 forloops will make form some big O notation, I hope it won’t freeze Your CPU :stuck_out_tongue: