I have a string
name = \"Ben\"
that I turn into a list
word = list(name)
I want to replace the characters
I want to replace the characters of the list with asterisks. How can I do this?
I will answer this question quite literally. There may be times when you may have to perform it as a single step particularly when utilizing it inside an expression
You can leverage the str.translate method and use a 256 size translation table to mask all characters to asterix
>>> name = "Ben"
>>> name.translate("*"*256)
'***'
Note because string is non-mutable, it will create a new string inside of mutating the original one.