HassanK HassanK - 6 days ago 5
Python Question

Changing all values of string to a certain value

input = ["AB0","A","BBBB"]
output = ["000","0","0000"]


Is there a function like
.replace("", "")
which could take in any input and give a string of zeros with the same number of characters?

Answer

This will work:

input  = ["AB0","A","BBBB"]

output = ["0"*len(x) for x in input]

or the same:

input  = ["AB0","A","BBBB"]
output = []
for x in input:
    output.append("0"*len(x))
Comments