我正在编写一个伪代码,我希望重复以下两个“for”循环,直到 data_changes 和 modem_changes 中的所有键都相同,即不应有任何键存在 data_changes 但 modem_changes 中不存在,反之亦然。在此之后我应该能够编写 Python 实现;任何人都可以提供输入吗?编辑:
我更感兴趣
- 如何为一个存在而不是另一个的键调用 func1 和 func2
2.重复 for 循环,直到 data_changes 和 modem_changes 中的键相同
data_changes = {
'253036': [''],
'313115': ['313113']
}
modem_changes = {'305403': [],
'311957': ['253036', '312591']
}
s1 = set(data_changes.keys())
s2 = set(modem_changes.keys())
value1 = s2.difference(s1)
print value1
value2 = s1.difference(s2)
print value2
def func1 (data_changes,key):
if key == '311957':
output = ''
if key == '305403':
output = ''
return output
def func2 (modem_changes,key):
if key == '313115':
output =''
if key == '253036':
output=''
return output
def method(d1, f1, d2, f2):
s1 = set(d1.keys())
s2 = set(d2.keys())
for k in s2.difference(s1):#set(['311957', '305403'])
f1(d1, k) # k in d2 not in d1.
for k in s1.difference(s2):#set(['313115', '253036'])
f2(d2, k) # k in d1 not in d2.
while(True):
method(data_changes, func1, modem_changes, func2)
value = set(data_changes.keys()) - set(modem_changes.keys())
print value
if value == set([]):
break;
EXPECTED OUTPUT:-
data_changes = {
'253036': [''],
'313115': ['313113']
'305403':['']
'311957':['']
}
modem_changes = {'305403': [],
'311957': ['253036', '312591']
'253036':[]
'313115':[]
}