-1
我必須在Python中實現下面的僞代碼。Python for循環單線程連接2個字符串
dict = {}
list1 = [1,2,3,4,5,6]
list2 = [2,4,5,7,8]
dict['msg'] = "List 2 items not in list 1 : "
for x in list 2:
if x in list1:
dict['msg'] += x
<write in log : dict['msg']>
如果我使用味精的價值列表
dict['msg'] = ["List 2 items not in list 1 : "]
我可以追加在單排的值作爲
[dict['msg'].append(x) for x in L2 if x not in L1]
但隨後的輸出頁面上的結果將作爲
msg : [
"List 2 items not in list 1 :",
7,
8
]
我想要結果si斜線爲
msg : List 2 items not in list 1 : 7,8
我該如何做到這一點?
因爲我需要爲其餘代碼的字典。 – pratibha
已更新的回答。 –