Change entries in list Python

Build a list L which should contain 7 integers 0 and 1. Write program to check is there different entries than 0 and 1 and if is, change that entries to 1.

L = [0, 1, 2, 1, 4, 0, 3]
i = 0
while i < len(L):
    if L[i] == 0:
        pass
    elif L[i] == 1:
        pass
    else:
        L[i] = 1
    i += 1
print(L)
[0, 1, 1, 1, 1, 0, 1]

  

Коментари

Популарни постови са овог блога

Python Fan functions

Python StopWatch milliseconds

Python Accounting