0

I have a piece of python code

def getAvailableLetters(lettersGuessed):
    str='abcdefghijklmnopqrstuvwxyz'
    for i in lettersGuessed:
        if i in str:
            str.replace(i,'')
    return str
getAvailableLetters(['a','v','k','k','l','i','o','0'])

The problem is that str.replace(i,'') doesn't work. Please help me in understand why?

Sunny Patel
  • 7,830
  • 2
  • 31
  • 46
Cloud JR K
  • 181
  • 1
  • 1
  • 7

1 Answers1

3

str.replace(i,'') doesn't not change the actual string, you would need

str = str.replace(i,'')
scharette
  • 9,437
  • 8
  • 33
  • 67
  • 1
    Note that `str` is a terrible name for a variable, since `str` is the built-in name for the string type. – Adam Smith Jul 30 '18 at 17:26
  • @AdamSmith True. – scharette Jul 30 '18 at 17:26
  • See the "Answer Well-Asked Questions" section of [How to Answer](https://stackoverflow.com/help/how-to-answer), particularly the bullet point regarding questions which "*have already been asked and answered many times before*". – Charles Duffy Jul 30 '18 at 17:27
  • @CharlesDuffy Thank you for the link. Honestly it is the first time I see the linked duplicate and I just went and upvoted it. I won't answer that type of question in the future. – scharette Jul 30 '18 at 17:28