我正在寫一個僞代碼,我希望重複下面兩個「for」循環,直到data_changes和modem_changes中的所有鍵都相同,即不應該存在任何存在data_changes的鍵,但是不在modem_changes中,反之亦然。我應該可以在這之後編寫Python實現;任何人可以提供投入? 編輯:for循環的控制流程
我更感興趣的
- 如何調用該存在於一個,而不是其他
2.repeating for循環,直到鍵鍵FUNC1和FUNC2在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':[]
}
@Mike - 它不僅僅是兩組交叉點..還有更多的嘗試..更多關於如何實現這個控制流的困惑.. – user2125827 2013-04-30 05:56:57
'data_changes.update(modem_changes)';-) – 2013-04-30 06:07:36
@LennartRegebro - 更新有什麼作用? – user2125827 2013-04-30 06:09:56