我是python的新手,正在尝试将两个对象与两个元素合并为一个元组?
我尝试过合并列表,对列表求和,等等,没有任何工作如我所愿。我提供的代码也不起作用。
def merge(dict1,dict2):
for key in dict2:
if key in dict1:
dict2[key]=dict2[key]+dict1[key]
else:
pass
return dict2
输入是这样:
a = {'x': [1,2,3], 'y': 1, 'z': set([1,2,3]), 'w': 'qweqwe', 't': {'a': [1, 2]}, 'm': [1]}
这:
b = {'x': [4,5,6], 'y': 4, 'z': set([4,2,3]), 'w': 'asdf', 't': {'a': [3, 2]}, 'm': "wer"}
我希望输出为:
{'x': [1,2,3,4,5,6], 'y': 5, 'z': set([1,2,3,4]), 'w': 'qweqweasdf', 't': {'a': [1, 2, 3, 2]}, 'm': ([1], "wer")}
其中^这是一个元组。
答案 0 :(得分:0)
鉴于类型太多,需要进行很多类型检查,但是这种简单的递归应该有效。
此外,这还假设private void ExportItems(MAPIFolder folder)
{
Directory.CreateDirectory(ExportPathField.Text + folder.FullFolderPath);
Items items = folder.Items;
if (items.Count > 0)
{
for (int counter = 1; counter <= items.Count; counter++)
{
object item = items[counter];
switch (Microsoft.VisualBasic.Information.TypeName(item))
{
case "MailItem":
MailItem mailitem = item as MailItem;
mailitem.SaveAs(ExportPathField.Text + folder.FullFolderPath + @"\" + mailitem.ReceivedTime.ToOADate() + ".msg");
System.Runtime.InteropServices.Marshal.ReleaseComObject(mailitem);
mailitem = null;
break;
case "MeetingItem":
MeetingItem meetingitem = item as MeetingItem;
meetingitem.SaveAs(ExportPathField.Text + folder.FullFolderPath + @"\" + meetingitem.ReceivedTime.ToOADate() + ".msg");
System.Runtime.InteropServices.Marshal.ReleaseComObject(meetingitem);
meetingitem = null;
break;
default:
break;
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
item = null;
}
}
for(int counter = 1; counter <= folder.Folders.Count; counter++)
{
ExportItems(folder.Folders[counter]);
}
}
和Outlook.Application app = new Outlook.Application();
Outlook.NameSpace outlookNs = app.GetNamespace("MAPI");
Outlook.MAPIFolder emailFolder = outlookNs.Folders[POBoxField.Text];
ExportItems(emailFolder);
中的键与示例中的键相同。
a