2 या अधिक dictionaries में key-value का overkill और *args के माध्यम से नई dictionary में coincidence का recording
📁 शब्दकोश, पायथन, मदद, त्रुटि
दो dictionaries हैं, दोनों dictionaries में key-value को sort out करना है। FOR cycle और *args parameter का उपयोग करके समान key-value को compare करें। पाए गए समान key-value को नई dictionary में add करें।
operator_one = {2: 'break', 1: 'pass', 3: 'print', 4: 'yield', 5: 'try'} operator_two = {1: 'pass', 2: 'global', 3: 'yield', 4: 'print', 5: 'try'} def find_common(*args): common_dict = {} if len(args) < 2: return common_dict keys_in_first = set(args[0].keys()) for key in keys_in_first: value = args[0][key] all_match = True for d in args[1:]: if key not in d or d[key] != value: all_match = False break if all_match: common_dict[key] = value return common_dict result = find_common(operator_one, operator_two) print(result)