list = [3,7,0,5,1,8]
for i in range(len(list)):
if list[i]<5:
list[i] = 0
elif list[i]>5:
list[i] = 1
print(list)
结果:
[0, 1, 0, 5, 0, 1]
list = [3,7,0,5,1,8]
for i in range(len(list)):
if list[i]<5:
list[i] = 0
elif list[i]>5:
list[i] = 1
print(list)
结果:
[0, 1, 0, 5, 0, 1]