HassanK HassanK - 1 year ago 63
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 Source

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:
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download