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 Programming: Write a RegEx that validates social security numbers
              Python Programming: Write a RegEx that validates social security numbers
              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: 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 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....
              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 PROGRAM: Write a program that determines the day of the week for any given calendar...
              PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar date after January 1, 1900, which was a Monday. This program will need to account for leap years, which occur in every year that is divisible by 4, except for years that are divisible by 100 but are not divisible by 400. For example, 1900 was not a leap year, but 2000 was a leap year.
              For Python: In this assignment you are asked to write a Python program to determine the...
              For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
              1- write down ways you could try using staffing activities to achieve equally effective matches for...
              1- write down ways you could try using staffing activities to achieve equally effective matches for new job applicants. For example, for the medical claims adjuster job, you might develop a special recruitment advertisement explaining the exact claims knowledge needed, develop a knowledge test to be used as part of the selection process, and have a higher starting pay for the most knowledgeable applicants to whom you make employment offers. a) Next, think of a time on your current job...
              ADVERTISEMENT
              ADVERTISEMENT
              ADVERTISEMENT