I am working on a Python project. I am creating a subset dictionary from the main dictionary, the subset dictionary only takes the key, value pairs that are under keys: 'E', 'O', 'L'.
I found this code is working perfectly:
{key: self._the_main_dict[key] for key in self._the_main_dict.keys() & {'E', 'O', 'L'}}
However, I would like to understand how it works. How could this be expressed in multiple lines of code? I guess it is something like: for key in ....