亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將字典中的所有列表相互比較

將字典中的所有列表相互比較

繁星coding 2021-07-07 16:57:11
在python中是否可以比較以下結構中的所有對象我有一個列表字典,每個列表中都有對象,例如[      [object1,object2,object3],      [object4,object5,object6],      [object7,object8,object9],]我想通過每個列表中的屬性將所有對象相互比較,并確定每個列表中沒有哪些對象。根據反饋,請參閱下面的示例from collections import defaultdictfrom pprint import pprintclass mytest:  def __init__(self, no, description):    self.no = no    self.description = descriptiondata = []x = mytest(1,'test1')x2 = mytest(2,'test1')x3 = mytest(1,'test2')x4 = mytest(2,'test2')x5 = mytest(3,'test2')x6 = mytest(1,'test3')x7 = mytest(2,'test3')x8 = mytest(4,'test3')data.append(x)data.append(x2)data.append(x3)data.append(x4)data.append(x5)data.append(x6)data.append(x7)data.append(x8)groups = defaultdict(list)for obj in data:    groups[obj.description].append(obj)new_list = groups.values()#i want to find out what items are not in each listfor list in new_list:    pprint(list)#example x8 = mytest(4,'test3') is only in one of the list so is missing from list 1 and 2希望這會有所幫助
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 187 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號