Проверьте наличие нескольких пар значений в словаре ⇐ Python
-
Гость
Проверьте наличие нескольких пар значений в словаре
Is there a way to shorten this code?
I want to print something if both a, b is in the dic, or a-foo, b-foo is in the dic or a-bar, b-bar is in the dic. Consider -foo and -bar to be fixed values.
Can I join the multiple if-s with or statements?
The dict looks like this:
defaultdict(, {'key1': {'elem1', 'elem2'}}) if "a" in my_dic["key1"] and "b" in my_dic["key1"]: print("Exists") if "a-foo" in my_dic["key1"] and "b-foo" in my_dic["key1"]: print("Exists") if "a-bar" in my_dic["key1"] and "b-bar" in my_dic["key1"]: print("Exists")
Источник: https://stackoverflow.com/questions/781 ... dictionary
Is there a way to shorten this code?
I want to print something if both a, b is in the dic, or a-foo, b-foo is in the dic or a-bar, b-bar is in the dic. Consider -foo and -bar to be fixed values.
Can I join the multiple if-s with or statements?
The dict looks like this:
defaultdict(, {'key1': {'elem1', 'elem2'}}) if "a" in my_dic["key1"] and "b" in my_dic["key1"]: print("Exists") if "a-foo" in my_dic["key1"] and "b-foo" in my_dic["key1"]: print("Exists") if "a-bar" in my_dic["key1"] and "b-bar" in my_dic["key1"]: print("Exists")
Источник: https://stackoverflow.com/questions/781 ... dictionary