私は以下を持っており、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']