1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ymorist [56]
4 years ago
5

Write a Python program to replace at most 2 occurrences of space, comma, or dot with a colon. Hint: use re.sub(regex, "newtext",

string, number_of_occurences)
Computers and Technology
1 answer:
charle [14.2K]4 years ago
7 0

Explanation:

The "re" module in python provides various functions to perform complex string operations easily.

For example, you can check whether a specific word exists in a given string or to replace it with some other word.  

Some of the functions in the re module are:

re.findall

re.search

re.sub()

We are particularly interested in the re.sub() function, we can use this function to replace the occurrences of space, coma or dot with semicolon.  

Syntax:

re.sub(pattern, replace, target_string, n).  

Where pattern = space, coma or dot  

replace = semicolon  

target_string = any string containing spaces, coma and dots

n = number of times you want the replacement to be done  

Code:

import re  

target_string = "Hello world,code,code."  

replace = ":"

pattern = "[ ,.]"

print(target_string)

print(re.sub(pattern, replace, target_string, 2) )

Output:

Hello world,code,code.

Hello:world:code,code.

It replaced the first white space and coma with semicolon, if we increase the n to 4 then the output is

Hello:world:code:code:

As expected, it replaced all of the space, coma, and dots with semicolons.

You might be interested in
Assembling parts and using various machines to create a final product is the process of ______.
s2008m [1.1K]

Answer:

Hey bro! Sorry to bother. But have any of your questions got deleted after posting them? I don't know why my question got deleted by a guy.

Explanation:

8 0
4 years ago
I’m nobody. Who are you?
stepan [7]

Answer:

The poet praises the common man.

Explanation:

8 0
3 years ago
Read 2 more answers
Write the working of dot matrix printer?<br><br>no links<br>​
lbvjy [14]

The working of dot matrix printer is provided in the picture.

4 0
3 years ago
Go to the Subset tab, which gives a subset of randomly chosen data from the first tab. Go to your Math Tools and open the Graph
Karo-lina-s [1.5K]

A linear regression model is used to show the relationship between variables on a scatter plot

The equation of the linear regression model is: \^y = 1.56\^x + 1.29 and the correlation coefficient is 0.8034

<h3>How to determine the equation of the linear regression</h3>

The question is incomplete. So, I will make use of a dataset that has the following calculation summary (from a graphing calculator)

  • Sum of X = 45
  • Sum of Y = 83
  • Mean X = 4.5
  • Mean Y = 8.3
  • Sum of squares (SSX) = 82.5
  • Sum of products (SP) = 128.5
  • The value of R is 0.8034.

The equation of the linear regression model is:

\^y = 1.56\^x + 1.29

See attachment for the scatter plot

Read more about linear regression model at:

brainly.com/question/26347582

5 0
3 years ago
In every programming language, when you access data stored in an array, you must use a ____ containing a value that accesses mem
Juli2301 [7.4K]

Answer: this app allow  u to have answers made for students 5 star ap but there are some ads that get  in the way

Explanation:

but it is good

7 0
3 years ago
Other questions:
  • Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile &gt;&gt; x &gt;&gt; y;
    13·1 answer
  • __________ ensures that the individual is who they claim to be (the authentic or genuine person) and not an imposter.
    15·1 answer
  • A(n) __________ is the unit of file I/O accessed by an application program as a single unit. A(n) __________ is the unit of stor
    5·1 answer
  • Methods used to change variables are called ______. equals accessors toString void mutators
    5·1 answer
  • A collection of methods that can be used by any class, as long as the class provides a definition to override the collection's a
    5·1 answer
  • A customer contacts the help disk stating a laptop does not remain charged for more than 30 minutes and will not charge more tha
    9·1 answer
  • The local area network software called a ____ server provides workstations with the authorization to access a particular printer
    13·1 answer
  • How do you program a computer
    7·1 answer
  • Plz tell the answer I I'll mark u as the brainliest
    14·1 answer
  • ((Sorry for the self promo btw) Can you guys help me try and get affiliate on twitch? I am currently at 20 followers and it woul
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!