Help with replacing all numbers with the letter 'd'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • richgirl
    New Member
    • Oct 2013
    • 1

    Help with replacing all numbers with the letter 'd'

    this wont work in codewrite when i import 're' is there another way?

    Example 'aa1aa2aa3' should change to 'aadaadaad'


    Code:
    st = raw_input("Enter string: ")
    
    def discover_digits(st):
    
    ....import re
    ....digit = re.sub('\d', 'd', 'aa1aa2aa3') # \d means  \   .........any digit
    ....print digit
    ....return digit
    
    discover_digits(st)
    Last edited by Rabbit; Oct 18 '13, 04:27 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Code:
    orig_string = "aa1aa2aa3"
    output_string = ""
    for letter in orig_string:
        if letter.isdigit() :
            output_string += "d"
        else:
            output_string += letter
    print output_string

    Comment

    Working...