473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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'


Expand|Select|Wrap|Line Numbers
  1. st = raw_input("Enter string: ")
  2.  
  3. def discover_digits(st):
  4.  
  5. ....import re
  6. ....digit = re.sub('\d', 'd', 'aa1aa2aa3') # \d means  \   .........any digit
  7. ....print digit
  8. ....return digit
  9.  
  10. discover_digits(st)
Oct 18 '13 #1
1 1296
dwblas
626 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. orig_string = "aa1aa2aa3"
  2. output_string = ""
  3. for letter in orig_string:
  4.     if letter.isdigit() :
  5.         output_string += "d"
  6.     else:
  7.         output_string += letter
  8. print output_string 
Oct 22 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Sorby | last post by:
Hi I've been coding in PHP for a little while now and was starting to feel pretty confident but then realise I need to understand regular expressions to solve a particular problem I've got ......
2
by: John Smith | last post by:
Hi, I'm just trying to work out the postage costs for a shopping cart and for some reason (possibly me being silly) i can't get the following to work : Dim strWeight3, strWeight4 strWeight3 =...
11
by: 05l8kr | last post by:
Struggling greatly here with C++ but I find it interesting at the same time. Any good books to buy or web sites to help with this program? For the following - I'm suppose to replace the first...
2
by: narpet | last post by:
Hello all. I posted this in the Visual Basic forum, but since it has to do with VBA and both Access and Excel share VBA (somewhat) I was hoping someone here would be able to help me... I have a...
3
by: bellino771 | last post by:
Hey guys. I'm having trouble gettin numbers from one file to another. There are nine sets of numbers in a text file in the format 2.34334, 42.34342, 34.453344, with each set of numbers on a new...
0
by: TONY-GAL | last post by:
To: All European Citizens who care about Animals This is a critical time. The European Commission (EC) is currently revising the law - known as Directive 86/609 - that governs animal experiments...
1
by: susan10 | last post by:
Im new to Coldfusion, and here is what i would like to do: I'm using a html-editor on one cfm-page, and saving the text in a database: --mytext written i the html-editor ----------------------...
4
by: sandvet03 | last post by:
I am trying to expand on a earlier program for counting subs and now i am trying to replace substrings within a given string. For example if the main string was "The cat in the hat" i am trying to...
0
by: David Pratt | last post by:
Hi. I am trying to replace a system call with a subprocess call. I have tried subprocess.Popen and subprocess.call with but have not been successful. The command line would be: svnadmin dump...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.