The contains_acronym function checks the text for the presence of 2 or more characters or digits surrounded by parentheses, with at least the first character in uppercase (if it's a letter), returning True if the condition is met, or False otherwise. For example, "Instant messaging (IM) is a set of communication technologies used for text-based communication" should return True since (IM) satisfies the match conditions." Fill in the regular expression in this function:

Respuesta :

Answer:

Following are the code to this question:

import re#import package regular expression

def contains_acronym(val): #defining a method contains_acronymn that accepts text value in parameter

   match= r"\([A-Z1-9][a-zA-Z1-9]*\)"#defining match variable that uses upper case, number, and lower case value  

   r= re.search(match, val)#defining r varaible that uses search method to search values

   return r!= None #use return keyword  

val="Instant messaging (IM) is a set of communication technologies used for text-based communication"

print(contains_acronym(val))#use print function to call method and print its return value

Output:

True

Explanation:

In the above-given code, first, we import package "regular expression" this package is used to check the string, In the next line, a method "contains_acronym" is defined that accepts a "val" variable in its parameters.

  • Inside the method, the "match" variable is defined that holds the uses upper case, number, and lower case values, and in the r variable the "search" method is defined, that search these and return the value.
  • Outside the method, val variable is defined, that store string value and use print method is used that calls the method "contains_acronym".