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
svlad2 [7]
3 years ago
14

Using Python

Computers and Technology
1 answer:
Mnenie [13.5K]3 years ago
8 0

Answer:

#section 1

import re

thesaurus = {

   "happy" : "glad",

   "sad" : "bleak",

   }

text =input('Enter text: ').lower()

#section 2

def synomReplace(thesaurus, text):

<em> # Create a regular expression  from the dictionary keys </em>

 regex = re.compile("(%s)" % "|".join(map(re.escape, thesaurus.keys())))

 

 # For each match, look-up corresponding value in dictionary

 return regex.sub(lambda x: thesaurus[x.string[x.start():x.end()]].upper(), text)

print(synomReplace(thesaurus, text))

Explanation:

#section 1

In this section, the regular expression module is imported to carry out special string operations. The thesaurus is initialized as a dictionary. The program then prompts the user to enter a text.

#section 2

In the section, we create a regular expression that will search for all the keys and another one that will substitute the keys with their value and also convert the values to uppercase using the .upper() method.

I have attached a picture for you to see the result of the code.

You might be interested in
A gui allows you to interact with objects on the screen such as icons and buttons true or false
Alja [10]

Answer:

True

Explanation:

7 0
3 years ago
Which of the following is a good precaution to take when making online purchases? (1 point)
Fantom [35]

Answer:

A.

Explanation:

A is the answer..

This is because you can use a private browser for safety precautions so no hackers would target you and steal your personal information. Also the other options make no sense at all. Option B states that you can use the same strong password for all online accounts and that's not good. It's not recommended because hackers or other people on the dark web can hack into your accounts and steal your data. Option C states that you must make sure http: and an open padlock displays on the address bar. This means that your connection is insecure and people can track you down. Option D is a good thing to do but option A is the best option overall. It's the right step to take when making online purchases <3

5 0
3 years ago
When elements are placed on the page so that text and graphic elements are evenly distributed you have:
Mashcka [7]
When elements are placed on the page so that text and graphic elements are evenly distributed you have: balance.
6 0
3 years ago
_____________________________________________________is a pre-designed format to help users with the creation of a document, lik
Naily [24]
C template......................................
8 0
3 years ago
What is causing the electricity prices to increase in South Africa?​
Pepsi [2]
The law of demand says that the higher the price of a good is, the less people will demand it. But South Africa , sales of electricity have been dropping, yet the utility wants consumers to even pay more for its good. The national utility, South Africa wants consumers to pay more for electricity.
4 0
3 years ago
Other questions:
  • You're working at a large industrial plant and notice a tag similar to the one shown in the figure above. Which of the following
    5·1 answer
  • Which of the preventive strategies is described below: Violence often escalates. Behaviors like excessive complaing, hostility,
    10·1 answer
  • You are holding a rock tied to a string, which is an example of a pendulum. identify and explain the proper term for each part o
    10·2 answers
  • Movies may depict larger-than-life situations, such as calamities, superheroes, and spaceships. A helps show such extraordinary
    11·1 answer
  • When using correct ergonomic technique be sure to
    6·2 answers
  • An investor is considering in which of two start-up companies to invest. The investor has faith in the industrial organization (
    9·2 answers
  • The loss of privacy data has implications:
    5·1 answer
  • What tool can you use to discover vulnerabilities or dangerous misconfigurations on your systems and network
    5·1 answer
  • How can the system administrator give the executive assistant the ability to view, edit, and transfer ownership of all records,
    6·1 answer
  • Which artificial intelligence term is used to describe extracting information from unstructured text.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!