- 列表中的值为字符串:
list_a = ['False', 'False', 'False', 'True', 'False', 'False', 'True']
list_b = ['True', 'False', 'False', 'False', 'True', 'False', 'True']
list_a1 = []
for i in list_a:
if i == 'False':
list_a1.append('0')
else:
list_a1.append('1')
print('list_a1:', list_a1)
list_b1 = []
for i in list_b:
if i == 'False':
list_b1.append('0')
else:
list_b1.append('1')
print('list_b1', list_b1)
list_same = []
for j in range(len(list_a1)):
if list_a1[j] == list_b1[j]:
list_same.append('0')
else:
list_same.append('1')
print('list_same', list_same)
'''
print:
list_a1: ['0', '0', '0', '1', '0', '0', '1']
list_b1 ['1', '0', '0', '0', '1', '0', '1']
list_same ['1', '0', '0', '1', '1', '0', '0']
'''
- 列表中的值为布尔:
list_image_2 = []
for i in range(len(list_image)):
if list_image[i] == False:
list_image_2.append('1')
else:
list_image_2.append('0')