import re 
s = 'ACBCAC'
For the given string, which of the following regular expressions can be used to check if the string starts with 'AC'?

Practice More Questions From: Quiz 1

Q:

“What will be the output of the following code? import restring = ‘bat, lat, mat, bet, let, met, bit, lit, mit, bot, lot, mot’result = re.findall(‘b[ao]t’, string)print(result)

Q:

Assume a and b are two (20, 20) numpy arrays. The L2-distance (defined above) between two equal dimension arrays can be calculated in python as follows:def l2_dist(a, b): result = ((a – b) * (a – b)).sum() result = result ** 0.5 return result Which of the following expressions using this function will produce a different result from the rest?

Q:

Consider the following variables in Python: a1 = np.random.rand(4)a2 = np.random.rand(4, 1)a3 = np.array([[1, 2, 3, 4]])a4 = np.arange(1, 4, 1)a5 = np.linspace(1 ,4, 4)Which of the following statements regarding these variables is correct?

Q:

Which of the following is the correct output for the code given below? import numpy as npold = np.array([[1, 1, 1], [1, 1, 1]])new = oldnew[0, :2] = 0print(old)

Q:

Given the 6×6 NumPy array r shown below, which of the following options would slice the shaded elements?

Q:

What will be the output of the variable L after the following code is executed? import res = ‘ACAABAACAAAB’result = re.findall(‘A{1,2}’, s)L = len(result)

Q:

import re s = ‘ACBCAC’For the given string, which of the following regular expressions can be used to check if the string starts with ‘AC’?

Q:

Which of the following is the correct regular expression to extract all the phone numbers from the following chunk of text: Office of Research Administration: (734) 647-6333 | 4325 North QuadOffice of Budget and Financial Administration: (734) 647-8044 | 309 Maynard, Suite 205Health Informatics Program: (734) 763-2285 | 333 Maynard, Suite 500Office of the Dean: (734) 647-3576 | 4322 North QuadUMSI Engagement Center: (734) 763-1251 | 777 North UniversityFaculty Adminstrative Support Staff: (734) 764-9376 | 4322 North Quad

Q:

Which of the following regular expressions can be used to get the domain names (e.g. google.com, www.baidu.com) from the following sentence? ‘I refer to https://google.com and I never refer http://www.baidu.com if I have to search anything’

Q:

The text from the Canadian Charter of Rights and Freedoms section 2 lists the fundamental freedoms afforded to everyone. Of the four choices provided to replace X in the code below, which would accurately count the number of fundamental freedoms that Canadians have? text=r”’Everyone has the following fundamental freedoms: (a) freedom of conscience and religion; (b) freedom of thought, belief, opinion and expression, including freedom of the press and other media of communication; (c) freedom of peaceful assembly; and (d) freedom of association.”’import repattern = Xprint(len(re.findall(pattern,text)))

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments