I need to make a dictionnary containing only keys.
I cannot use d.append() as it is not a list, neither setdefault as it needs 2 arguments: a key and a value.
It should work as the following:
d = {}
add "a":
d = {"a"}
add "b":
d = {"a", "b")
add "c" ...
#Final result is
d = {"a", "b", "c"}
What is the code I need to get this result? Or is it another solution? Such as making a list.
l = ["a", "b", "c"] # and transform it into a dictionnary: d = {"a", "b", "c"} ?
That should do it:
l = ["a", "b", "c"]
d = {k:None for k in l}
As @Rahul says in the comments, d = {"a", "b", "c"} is not a valid dictionary definition since it is lacking the values. You need to have values assigned to keys for a dictionary to exist and if you are lacking the values you can just assign None and update it later.
You need a set not a dictionary,
l = ["a", "b", "c"]
d = set(l)