How to use Python sets and add strings to it in as a dictionary value

You can write a single element tuple as @larsmans explained, but it is easy to forget the trailing comma. It may be less error prone if you just use lists as the parameters to the set constructor and methods:

Dictionary[key_1] = set(['name'])    
Dictionary[key_2] = set(['name_2', 'name_3'])

Dictionary[key_2].add(['name_3'])

should all work the way you expect.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)