Question

1. (Python) If the strings r and s are defined by r = 'ab25wyz9utb725cd' s =...

1. (Python) If the strings r and s are defined by
r = 'ab25wyz9utb725cd'
s = r'\d+'
what is the output?
import re
print(re.findall(r, s))
a. ['ab', 'wyz', 'utb', 'cd']
b. ['ab', '25', 'wyz', '9', 'utb', '725', 'cd']
c. ['25', '9', '725']
d. [25, 9, 725]

2. (Python) If the strings r and s are defined by
r = 'ab25wyz9utb725cd'
s = r'\d+'
what is the output?
import re
print(re.split(r, s))
a. ['ab', 'wyz', 'utb', 'cd']
b. ['ab', '25', 'wyz', '9', 'utb', '725', 'cd']
c. ['25', '9', '725']
d. [25, 9, 725]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(1)

In python, \d means a decimal digit [0-9] eg. 4.6.77, 89,724, ..

in our given question 1 the statement print(re.findall(r, s)) will print all digit which is present in the string r.

After running the above code, image of source code -

So, above we can say the correct output of the given code is an option (c).

(2) In python re.split() split a string that matches a regular expression, and it specifies the regular expression pattern in the first parameter and the target character string in the second parameter.

After running the given code in question 2, the output can be seen as

So form above we can say the correct output is option (c).

Please upvote the answer, if you have any doubts please ask in the comments section.Thanks

Add a comment
Know the answer?
Add Answer to:
1. (Python) If the strings r and s are defined by r = 'ab25wyz9utb725cd' s =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Page 3 of 7 (Python) For each substring in the input string t that matches the...

    Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub (r, o, t) substitutes the matching substring with the string a. Wwhat is the output? import re print (re.aub (r"l+\d+ " , "$, "be+345jk3726-45+9xyz")) a. "be$jk3726-455xyz" c. "bejkxyz" 9. b. "be$jks-$$xyz" d. $$$" A object a- A (2) 10. (Python) What is the output? # Source code file: A.py class A init (self, the x): self.x-...

  • I cant get this python program to read all the unique words in a file. It...

    I cant get this python program to read all the unique words in a file. It can only read the number of the unique words in a line. import re import string from collections import Counter # opens user inputted filename ".txt" and (w+) makes new and writes def main(): textname = input("Enter the file to search: ") fh = open(textname, 'r', encoding='utf-8' ) linecount = 0 wordcount = 0 count = {} print("Sumary of the", fh) for line in...

  • solve with python Write a recursive function recStringWithLenCount() that takes a one-dimensional list of strings as...

    solve with python Write a recursive function recStringWithLenCount() that takes a one-dimensional list of strings as a parameter and returns the count of strings that have at least the length of second parameter passed into the function that are found in the list. Recall that you can determine whether an item is a string by writing type(item) == str. The only list functions you are allowed to use are len(), indexing (lst[i] for an integer i), or slicing (lst[i:j] for...

  • I need python help .. I need to know if a user were to input 3...

    I need python help .. I need to know if a user were to input 3 commands to a program and run it such as specify: Usage: ./filemaker INPUTCOMMANDFILE OUTPUTFILE RECORDCOUNT (./filemaker is the program)( (INPUTCOOMANDFUILE= a text file that contains key words that need to be searched through then decided what to do ) (RECORDCOUNT= number) Given an input file that contains the following: That specifies the text, then the output, and the number of times to be repeated...

  • Please use Python def findSubstrings(s):     # Write your code here Consider a string, s = "abc"....

    Please use Python def findSubstrings(s):     # Write your code here Consider a string, s = "abc". An alphabetically-ordered sequence of substrings of s would be {"a", "ab", "abc", "b", "bc", "c"}. If the sequence is reduced to only those substrings that start with a vowel and end with a consonant, the result is {"ab", "abc"}. The alphabetically first element in this reduced list is "ab", and the alphabetically last element is "abc". As a reminder: • Vowels: a, e, i,...

  • Given relation R(A, B, C, D, E, F), give (i) the key(s) of R and (ii)...

    Given relation R(A, B, C, D, E, F), give (i) the key(s) of R and (ii) the normal form of R if the FDs are: (d) AB -> C, CD -> EF (e) AB -> CD, D -> EF, C -> AB. (f) ABC -> D, ABC -> E, ABC -> F.

  • Let S be the set of binary strings defined recursively as follows: Basis step: 0ES Recursive step...

    discrete math. Structural Induction: Please write and explain clearly. Thank you. Let S be the set of binary strings defined recursively as follows: Basis step: 0ES Recursive step: If r ES then 1rl E S and 0x0ES (I#x and y are binary strings then ry is the concatenation of and y. For instance, if 011 and y 101, then ry 011101.) (a) List the elements of S produced by te first 2 applications of the recursive definition. Find So, Si...

  • 1) Which of the following is NOT true about a Python variable? a) A Python variable...

    1) Which of the following is NOT true about a Python variable? a) A Python variable must have a value b) A Python variable can be deleted c) The lifetime of a Python variable is the whole duration of a program execution.   d) A Python variable can have the value None.        2) Given the code segment:        What is the result of executing the code segment? a) Syntax error b) Runtime error c) No error      d) Logic error 3) What...

  • in python I have a list of strings, some contain purely numbers while others are dates,...

    in python I have a list of strings, some contain purely numbers while others are dates, names, etc. I am trying to convert the strings containing only numbers into floats. this is the code I am using but it alwyas returns nothing. Python just says restart and nothing goes through. how can I get my code to do what I want? f = open('GOOG-HistoricalQuotest.txt','r+') ff=f.readlines() clean = [] lst = [] for i in range(2,len(ff)+1): try: [float(i) for i in...

  • python: how would I format the grid below so that it is aligned correctly? as you...

    python: how would I format the grid below so that it is aligned correctly? as you see, I tried to center it but it is still not correct. import random row=random.randint(1,10) col=random.randint(1,10) for r in range(row): for c in range(col): if r %2==0 and c %2==0: print(format('a','^3'),end=' ') elif r %2!=0 and c %2!=0: print(format("/x\\",'^3'),end=' ') elif c%2!=0: print(format('-','^3'),end='')    else: print(format('s','^3'),end=' ')    print() #go to next line current Output is: (example if random function choses col=4 and row=3)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT