There is such a dictionary: mydict = {'Main': 'Open', 'Second': 'Close', 'Third': 'Open'} . It is necessary to get all the keys to the values of 'open'
it displays only 'Open' ?
question@mail.ru
·
01.01.1970 03:00
There is such a dictionary: mydict = {'Main': 'Open', 'Second': 'Close', 'Third': 'Open'} . It is necessary to get all the keys to the values of 'open'
it displays only 'Open' ?
answer@mail.ru
·
01.01.1970 03:00
Lea list inclusions , they very often come in handy in python, because they allow you to make samples quite briefly and clearly:
MyDict = { 'Main' : 'open' , 'second' : 'clause' , 'Third' : 'open' } print ([k for k in in MyDICT if mydict [k] == "open" "]) conclusion:
[ 'main' , 'third' ]
this is essentially the same solution, only written into one line and without using a variable for accumulating to accumulate List.