2021年1月17日星期日

How to replace each string in a list with some other string in python [duplicate]

I'm making a hangman game, recently started python and looks like a good project I'd like to do, and so far its going great, I have a function that takes a string and puts it in a list like this:

Word: duck  List: ["d", "u", "c", "k"]  

Now I want to replace the D U C K letters with "_" I tried:

for char in List:     List.replace("d", "_")  

This doesn't do anything also I dont want to do it for every single letter separately I would like something like this:

for char in List:     List.replace(char, "_")  

I hope this is understandable

https://stackoverflow.com/questions/65768296/how-to-replace-each-string-in-a-list-with-some-other-string-in-python January 18, 2021 at 11:03AM

没有评论:

发表评论