检查python列表中是否存在列表
问题描述:
我需要检查列表列表中是否存在列表。我面临的问题是,我的名单是由类的对象,所以我不能够做到这一点使用正常 “在list_of_lists如果名单”的方法检查python列表中是否存在列表
我的代码的相关部分如下
for ind in feasible_pop_comp:
for other in feasible_pop_comp:
if ind.Type!= other.Type:
comp=[ind,other]
if comp not in self.candidate.list #does not work even with .any() or .all() included
dombool=self.compare_typematch(ind, other)
if (dombool==0):
replace=self.check_distance(ind.point,other.point)
if replace:
if(ind<other):
feasible_pop_comp.remove(other)
else:
feasible_pop_comp.remove(ind)
else:
self.candidate_list.append(comp)
我的类已经有内置的命令检查结构相似性与其它类的对象(读平等)
def __eq__(self, other):
return self.point == other.point# as all other parameters are derived from analysing the point, this equivalence is sufficient
回溯如下:
首次if comp not in self.candidate_list:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Failed !
它循环进入当self.candidate_list是空
正如你可能从我的unpythonic代码注意,我是比较新的蟒蛇。 在此先感谢。
“我的类已经有内置的命令检查与其它类对象的结构相似” inspectorG4dget 2012-02-10 16:47:40
我似乎并没有工作! – Sachiros 2012-02-10 16:48:32
向我们展示您的'__eq__'方法和回溯。 – senderle 2012-02-10 16:49:49