我有以下内容,需要一些关于 python 实现的指导..我清楚地记录了算法和预期的输出..任何输入都非常感谢..
data_changes ={'305403': ['302180'], '312994': ['311957'], '311957': ['312621'] }
modem_changes = {'305403': [], '313113': [], '312994': ['253036', '312591'], '311957': []}
for keys that are present in both data_changes and modem_changes:
write data to a file "file.txt" in the order key-->data_changes_values-->modem_changes_values
for keys that exist in only one of data_changes and modem_changes :
append data to the same file "file.txt" key--> data_changes_values or key-->modem_changes values
EXPECTED OUTPUT:-
Create a text file with the following data
305403 302180
312994 311957 253036 312591
311957 312621
313113
以下是我尝试过但没有达到我的目的......
build_dep_list= [i
for k, v in itertools.chain.from_iterable(d.iteritems() for d in (data_changes, modem_changes))
for i in [k] + (v or [])
if i]
print "BUILD LIST"
print list(set(build_dep_list))
CURRENT OUTPUT:-
['305403', '302180', '313113', '311957', '312621', '253036', '312994', '312591']