Извлечь подмножество пар ключ-значение из словаря? ⇐ Python
Извлечь подмножество пар ключ-значение из словаря?
I have a big dictionary object that has several key value pairs (about 16), but I am only interested in 3 of them. What is the best way (shortest/efficient/most elegant) to subset such dictionary?
The best I know is:
bigdict = {'a':1,'b':2,....,'z':26} subdict = {'l':bigdict['l'], 'm':bigdict['m'], 'n':bigdict['n']} I am sure there is a more elegant way than this.
Источник: https://stackoverflow.com/questions/535 ... dictionary
I have a big dictionary object that has several key value pairs (about 16), but I am only interested in 3 of them. What is the best way (shortest/efficient/most elegant) to subset such dictionary?
The best I know is:
bigdict = {'a':1,'b':2,....,'z':26} subdict = {'l':bigdict['l'], 'm':bigdict['m'], 'n':bigdict['n']} I am sure there is a more elegant way than this.
Источник: https://stackoverflow.com/questions/535 ... dictionary
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение