Python Dictionary Comparison: Correctly Comparing Values in a Nested Dictionary
No, the line 'if input['accessible_name'] == ele_name:' will not compare the value of 'input['accessible_name']' and 'ele_name' correctly.
In Python, the 'key()' method is used to get the key of a dictionary element, not to compare values. To compare the values, you should use the '==' operator directly without using 'key()'.
Here's the corrected code:
for input_list in data_ele['inputs'].values():
for input in input_list:
if input['accessible_name'] == ele_name:
# Your code here
In the corrected code, the values of 'input['accessible_name']' and 'ele_name' will be compared correctly.
原文地址: https://www.cveoy.top/t/topic/pcsV 著作权归作者所有。请勿转载和采集!