Python Forum
help with replacing charactersdef fix(block): alf = ['a', 'b', 'c', ' in a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with replacing charactersdef fix(block): alf = ['a', 'b', 'c', ' in a string
#1
I want to take a string and replace every letter in the string with the second to next letter in the alphabet. eg(a => c, b => d). My code changes the string does not save and will change back to the original string when changing the next letter. Thanks for any help


def fix(block):
    alf = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    cur = 0
    old = 0
    new = 2

    while cur < 26:
        new_block = []
        get = block.replace(alf[old], alf[new])
        old = old + 1
        new = new + 1
        cur = cur + 1
        return get
Reply


Messages In This Thread
help with replacing charactersdef fix(block): alf = ['a', 'b', 'c', ' in a string - by Marshall_99 - Apr-18-2017, 01:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replacing String Variable with a new String Name kevv11 2 805 Jul-29-2023, 12:03 PM
Last Post: snippsat
  Replacing a words' letters in a string cananb 2 3,500 Dec-01-2020, 06:33 PM
Last Post: perfringo
  Replacing characters in a string with a list cjms981 1 1,831 Dec-30-2019, 10:50 PM
Last Post: micseydel
  Replacing all letters in a string apart from the first letter in each word Carbonix 9 4,970 Jan-17-2019, 09:29 AM
Last Post: buran
  Replacing letters on a string via location Owenix 2 2,487 Sep-16-2018, 10:59 AM
Last Post: gruntfutuk
  Replacing variable in a split string and write new file python MyCode 1 3,572 Oct-30-2017, 05:20 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020