Change each character in string to the next character in alphabet

前端 未结 8 1122
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 15:45

I am coding in Python 2.7 using PyCharm on Ubuntu.

I am trying to create a function that will take a string and change each character to the character that would be

8条回答
  •  春和景丽
    2021-01-03 16:19

    Look at this for ideas to simplify your code.

    def LetterChanges(word):
        zabc  = 'abcdefghijklmonpqrstuvwxyzabc'
        ab_st = list(zabc)
        new_word = []    
        for letter in list(word.lower().strip()):        
            new_word.append(ab_st[zabc.index(letter) + 1])
        new_word = "".join(new_word)
        return new_word          
    
    
    LetterChanges("  Chicago ")
    

提交回复
热议问题