python判断两个列表是否一样
list1 = ['checkbox', 'account_id', 'create_by', 'relation', 'file_media', 'url', 'mul_select', 'person', 'phone', 'last_by', 'account_name', 'single_select', 'account_email', 'last_time', 'account_cre
·
list1 = ['checkbox', 'account_id', 'create_by', 'relation', 'file_media', 'url', 'mul_select', 'person', 'phone', 'last_by', 'account_name', 'single_select', 'account_email', 'last_time', 'account_create_time', 'create_time', 'number']
list2 = ['number', 'create_time', 'checkbox', 'account_create_time', 'single_select', 'account_name', 'last_by', 'phone', 'person', 'last_time', 'mul_select', 'url', 'file_media', 'relation', 'create_by', 'account_id','account_email']
#方法一:判断两个列表中的元素是否一样
list1.sort()
list2.sort()
count = 0
if len(list1) == len(list2):
for i in range(0,len(list1)):
if list1[i] == list2[i]:
count+=1
else:
print(False)
break
if count == len(list1):
print(True)
else:
pass
else:
print(False)
#方法二:判断两个列表中的元素是否一样,并能找出两个列表中不一样的元素
diff = list(set(list1).difference(set(list2)))
diff.extend(list(set(list2).difference(set(list1))))
print(diff)
if diff == []:
print(True)
else:
print(False)
更多推荐
已为社区贡献1条内容
所有评论(0)