我有一个如下的清单
list1 = [
('Ram','Laxman','Bharat','Sita'),
('Ram','Ravan','Bharat','Sita'),
('Ram','Luv','Dashrat','Sita'),
('Dasrath','Kekei','Bharat','Ram'),
('Laxman','Bharat','Ram','Hanuman'),
('Hanuman','Sita','Kekei','Ravan'),
('Ram','Sita','Hanuman','Ravan')
]
我想过滤至少有3个元组值匹配的列表数据,如果2个或更多元组至少有3个值匹配,那么列表中应该只有第一个元组和其余元组。 例如,在上面的列表中,我们有下面的列表元组,它有3个值匹配
result = [
('Ram','Laxman','Bharat','Sita'),
('Ram','Luv','Dashrat','Sita'),
('Dasrath','Kekei','Bharat','Ram'),
('Hanuman','Sita','Kekei','Ravan')
]
我觉得你的问题很有趣。我用一些矩阵运算来解决它。我认为这种方式比普通循环快得多
结果是:
相关问题 更多 >
编程相关推荐