Question

In: Computer Science

Regarding Python. 1. How would you write a regex that matches the hour of the day...

Regarding Python.

1.

How would you write a regex that matches the hour of the day from the extracted line shown below? (The highlighted portion)

From [email protected] Sat Jan 5 09:14:16 2008

Question options:

ˆFrom .+ [0-9] ˆX-.*: [0-9.]+ [0-9]:

ˆFrom .* [0-9][0-9]:

ˆFrom .* ('ˆX\S*: ([0-9.]+)', line)

    A _____________ sign at the end of the regular expression indicates that the string must end with the specified regex pattern.

    Question options:

    question (?)

    caret (^)

    dollar ($)

    0 / 1 point

      Which of the following will be a correct match for the regex "F..M"

      Question options:

      F!@M

      FRONM

      FOR

        Which of the following is used by Unix grep to match a character that is anything other than a space?

        Question options:

        "/S"

        "[ˆ ]"

        "/s"

          Python uses a ___________algorithm to search for keys in a dictionary?

          Question options:

          hash table

          reference list

          search engine

            _____________ is a special character that matches any character.

            Question options:

            Escape character

            Wild card

            Regular expression

              import re

              hand = open('mbox-short.txt')

              for line in hand:

              line = line.rstrip()

              if re.search('ˆFrom:.+@', line) :

              print line

              What is the correct interpretation of the highlighted portion of the script shown above?

              Question options:

              The search will match lines that end with "From:", followed by an @ sign, followed by zero or more characters.

              The search will match lines that start with "From:", followed by one or more characters, followed by an @ sign.

              The search will match lines that end with "From:", followed by a plus (+) sign, followed by an @ sign.

              Solutions

              Expert Solution

              Question1

              The correct option is C) ˆFrom .* ('ˆX\S*: ([0-9.]+)', line) ,
              This is because we need the second parameter which is the strign on which regex is to be applied , also we nned to seacrhc only the hour which is the first two digits and hence the given option

              Question 2

              The corretc option si option C) dollar ($) ,
              caret sign is used to match startign characters and ? is used to match a single character , $ is ised to match ending characters

              Question 3

              The correct option is option a F!@M

              . menas any character except line break so the qiven regex will match any word having 4 characters and so the first option

              Question 4

              The correct option will be option b[^ ]
              ^ enclosed in [] means not to include anything mentioned inside the barcket , in this case the space.

              Question 5

              The correct option i a) hash table

              python uses hash table algoritm to search for keys in a dictionary

              Question 6

              The correct option is b) wild card

              In regex wild cards are used to match any character

              Question 7

              The correct option is b) The search will match lines that start with "From:", followed by one or more characters, followed by an @ sign.

              ^ meatches the start of strign and .+ means 0 or more characters so option b


              Related Solutions

              Python regex How to write the regex in Python that only include the contents within a...
              Python regex How to write the regex in Python that only include the contents within a parentheses? e.g. "uio" [ek3k 0die] 4229834 return "ek3k 0die"
              Python Programming: Write a RegEx that validates social security numbers
              Python Programming: Write a RegEx that validates social security numbers
              HOW WOULD YOU WRITE THIS IN PYTHON? SHOW THIS IN PYTHON CODE PLEASE # DEFINE 'all_keywords',...
              HOW WOULD YOU WRITE THIS IN PYTHON? SHOW THIS IN PYTHON CODE PLEASE # DEFINE 'all_keywords', A LIST COMPRISED OF ALL OUR NEGATIVE SEARCH KEYWORDS AS REQUIRED BY THE PROJECT # FOR EACH ELEMENT IN 'full_list' (THE LIST OF LISTS YOU WOULD HAVE CREATD ABOVE THE PREVIOUS LINE) # INITIALIZE THE SET 'detected_keywords' TO EMPTY # DEFINE VARIABLE 'current_reviewer' FROM CURRENT ELEMENT OF 'full_list' BY EXTRACTING ITS FIRST SUB-ELEMENT,... # ...CONVERTING IT TO A STRING, AND THEN STRIPPING THE SUBSTRING...
              Write a Python program to manage league matches. Different teams can participate in a league. A...
              Write a Python program to manage league matches. Different teams can participate in a league. A player belongs to a team and a team can play many games in a league. For each team, the league wants to track the name of the team and the number of players in each team. The league also wants to track the number of games the team has played, and the total numbers of points scored across all games played. During each game,...
              FOR PYTHON: Write a python program for a car salesperson who works a five day week....
              FOR PYTHON: Write a python program for a car salesperson who works a five day week. The program should prompt for how many cars were sold on each day and then prompt for the selling price of each car (if any) on that day. After the data for all five days have been entered, the program should report the total number of cars sold and the total sales for the period. See example output. NOTE: duplicate the currency format shown...
              Python Problem Problem 1: In this problem you are asked to write a Python program to...
              Python Problem Problem 1: In this problem you are asked to write a Python program to find the greatest and smallest elements in the list. The user gives the size of the list and its elements (positive and negative integers) as the input. Sample Output: Enter size of the list: 7 Enter element: 2 Enter element: 3 Enter element: 4 Enter element: 6 Enter element: 8 Enter element: 10 Enter element: 12 Greatest element in the list is: 12 Smallest...
              Python: How would I write a function that takes a directory and a size in bytes,...
              Python: How would I write a function that takes a directory and a size in bytes, and returns a list of files in the directory or below that are larger than the size. For example, I can use this function to look for files larger than 1 Meg below my Home directory.
              Python: How would I write a function that takes a URL of a webpage and finds...
              Python: How would I write a function that takes a URL of a webpage and finds the first link on the page? The hint given is the function should return a tuple holding two strings: the URL and the link text.
              PYTHON--- regarding a hash table, why would it be bad to delete an item to successive...
              PYTHON--- regarding a hash table, why would it be bad to delete an item to successive searches or insertions that uses open addressing
              Python Coding 1. validate_username_password(username, password, users): This function checks if a given username and password matches...
              Python Coding 1. validate_username_password(username, password, users): This function checks if a given username and password matches in the stored users dictionary. This function returns True if a match found otherwise returns False. 2. validate_existing_user(users): This function asks for username and password and checks if user provided name and password matches. It prints an informational message and returns username if it does find a match. Call validate_username_password() function to perform this validation. A user has total of three chances to validate....
              ADVERTISEMENT
              ADVERTISEMENT
              ADVERTISEMENT