I want to use the following function in order mutate the elements of two lists: If a list element starts with a "U", the element should be mutated to "1", otherwise the list element should be mutated to "0". Here is the code:
def measure(p):
for x in range(len(p)):
if p[x][0] == 'U':
p[x] = 1
else:
p[x] = 0
return p
print measure(['Dave','Sebastian','Katy'])
print measure(['Umika','Umberto'])
The correct result should be
[0, 0, 0]
[1, 1]
But the current code produces:
[0, 'Sebastian', 'Katy']
[1, 'Umberto']
It seems that the iteration stopped after the first element. How can I solve this problem?