0

I have a tuple as follows:

tuple
{('A', 'B'), ('A', 'C'), ('B', 'C')}

I would like to create a dict and want to set its keys as the above tuple. Dictionary should look like following:

dict
{('A', 'B'): None,
 ('A', 'C'): None,
 ('B', 'C'): None}

How would I do it as easy as possible?

I tried this but does not work:

dict = {(set(tuple(sorted(x)): None for x in lines_tuple)}
oakca
  • 1,408
  • 1
  • 18
  • 40

1 Answers1

4

dict has a fromkeys method, which defaults the values to None if you don't pass any in:

original = {('A', 'B'), ('A', 'C'), ('B', 'C')}
new = dict.fromkeys(original)

new should now look like {('A', 'B'): None, ('B', 'C'): None, ('A', 'C'): None}

GammaGames
  • 1,617
  • 1
  • 17
  • 32