I am trying to find the keys of the dictionaries inside a dictionary and write them into a set using set/list comprehension.
So it looks like this:
dict_o_dicts = {
1: {'de': 'eins', 'en': 'one' },
2: {'de': 'zwei', 'en': 'two' },
3: {'ru': 'три', 'gr': 'τρία' },
0: {'ru': 'ноль' }}
I can get it working using:
result = set()
for x in dict_o_dicts:
for y in dict_o_dicts[x]:
result.add(y)
Gives the required output:
{'de', 'en', 'gr', 'ru'}
But I am required to solve it using a set/list comprehension. I tried everything, but I always get stuck somewhere. For example:
result = [set(dict_o_dicts[x].keys()) for x in dict_o_dicts]
It gives me a list of sets, but how could I unite them? I just don't know how to solve it in one line.