Computers and Technology

#Write a function called "in_parentheses" that accepts a #single argument, a string representing a sentence that
#contains some words in parentheses. Your function should
#return the contents of the parentheses.
#
#For example:
#
# in_parentheses("This is a sentence (words!)") -> "words!"
#
#If no text appears in parentheses, return an empty string.
#Note that there are several edge cases introduced by this:
#all of the following function calls would return an empty
#string:
#
# in_parentheses("No parentheses")
# in_parentheses("Open ( only")
# in_parentheses("Closed ) only")
# in_parentheses("Closed ) before ( open")
#
#You may assume, however, that there will not be multiple
#open or closed parentheses.
#Write your function here!
def in_parentheses(a_string):
import re
regex = re. compile(".*?\((.*?)\)")
result = re. findall(regex, a_string)
return(result)
#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print (including the blank lines):
#words!
#
#as he is doing right now
#
#
#!
print(in_parentheses("This is a sentence (words!)."))
print(in_parentheses("No parentheses here!"))
print(in_parentheses("David tends to use parentheses a lot (as he is doing right now). It tends to be quite annoying."))
print(in_parentheses("Open ( only"))
print(in_parentheses("Closed ) only"))
print(in_parentheses("Closed ) before ( open"))
print(in_parentheses("That's a lot of test cases(!)"))

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 17:10, madams4450
Ac++an of of pi. in , pi is by : pi = 4 – 4/3 + 4/5 – 4/7 + 4/9 - 4/11 + 4/13 - 4/15 + 4/17 . ., to pi (9 ). , if 5 to pi, be as : pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 = 4 – 1. + 0.8 - 0. + 0. = 3.. atoofbe to pi?
Answers: 2
image
Computers and Technology, 24.06.2019 18:00, valdezavery9018
Hacer un algoritmo que me permita ingresar el nombre de una parcela de terreno y muestre junto al mensaje “tipo de suelos: suelos fumíferos, ¡excelente!
Answers: 1
image
Computers and Technology, 25.06.2019 00:30, kukisbae
How do i take a screenshot on a laptop?
Answers: 2
image
Computers and Technology, 25.06.2019 05:00, adajadavis2843
Which of the following statements best deceive the relationship between carrying capacity and population size
Answers: 1
Do you know the correct answer?
#Write a function called "in_parentheses" that accepts a #single argument, a string representing a...

Questions in other subjects:

Konu
Social Studies, 18.02.2021 22:40
Konu
Mathematics, 18.02.2021 22:40