<jupyter_start><jupyter_text>Assignment 1For this assignment you are welcomed to use other regex resources such a regex "cheat sheets" you find on the web. Before start working on the problems, here is a small example to help you understand how to write your own answers. In short, the solution should be written within the function body given, and the final result should be returned. Then the autograder will try to call the function and validate your returned result accordingly.<jupyter_code>def example_word_count():
    # This example question requires counting words in the example_string below.
    example_string = "Amy is 5 years old"
    
    # YOUR CODE HERE.
    # You should write your solution here, and return your result, you can comment out or delete the
    # NotImplementedError below.
    result = example_string.split(" ")
    return len(result)

    #raise NotImplementedError()<jupyter_output><empty_output><jupyter_text>Part AFind a list of all of the names in the following string using regex.<jupyter_code>#**********************************************************************************************************
# Name : Assignment_1_A
# Author : <NAME> :: (www.prudhvy.com )
# Version : Version 1.0 
# Description : Answer for Assignment_1_A.
# Input : 
# Date : 31-May-2021
#************************************************************************************************************

import re
def names():
    simple_string = """Amy is 5 years old, and her sister Mary is 2 years old. 
    Ruth and Peter, their parents, have 3 kids."""
    match = re.findall('[A-Z]\w+',simple_string) 
    return match   
names
#raise NotImplementedError()
assert len(names()) == 4, "There are four names in the simple_string"<jupyter_output><empty_output><jupyter_text>Part BThe dataset file in [assets/grades.txt](assets/grades.txt) contains a line separated list of people with their grade in a class. Create a regex to generate a list of just those students who received a B in the course.<jupyter_code>#**********************************************************************************************************
# Name : Assignment_1_B
# Author : <NAME> :: (www.prudhvy.com )
# Version : Version 1.0 
# Description : Answer for Assignment_1_B.
# Input : 
# Date : 31-May-2021
#************************************************************************************************************
import re
def grades():
    with open ("assets/grades.txt", "r") as file:
        grades = file.read()
        Split_grades = grades.split('\n')
        # match = [grades for grades in grades.split() if grades.endswith('B')]
        list_Names = list()
        for gline in Split_grades:
            if not gline: continue
            Names_found = gline.split(':')
            Names_found = [x.strip(' ') for x in Names_found]
            if Names_found[1].endswith('B'):
                list_Names.append(Names_found[0])
    return list_Names

grades
    #raise NotImplementedError()
assert len(grades()) == 16<jupyter_output><empty_output><jupyter_text>Part CConsider the standard web log file in [assets/logdata.txt](assets/logdata.txt). This file records the access a user makes when visiting a web page (like this one!). Each line of the log has the following items:* a host (e.g., '172.16.17.32') * a user_name (e.g., 'feest6811' **note: sometimes the user name is missing! In this case, use '-' as the value for the username.**)* the time a request was made (e.g., '21/Jun/2019:15:45:24 -0700')* the post request type (e.g., 'POST /incentivize HTTP/1.1' **note: not everything is a POST!**)Your task is to convert this into a list of dictionaries, where each dictionary looks like the following:```example_dict = {"host":"172.16.17.32",                 "user_name":"feest6811",                 "time":"21/Jun/2019:15:45:24 -0700",                "request":"POST /incentivize HTTP/1.1"}```<jupyter_code>#**********************************************************************************************************
# Name : Assignment_1_C
# Author : <NAME> :: (www.prudhvy.com )
# Version : Version 1.0 
# Description : Answer for Assignment_1_C.
# Input : 
# Date : 31-May-2021
#************************************************************************************************************
import re

def merge_lists(list1, list2):
    merged_list = [(list1[i], list2[i]) for i in range(0, len(list1))]
    return merged_list

def logs():
    with open("assets/logdata.txt", "r") as file:
            logdata = file.read()
            Split_log = logdata.split('\n')
            Main_list = list()
            list_header = ['host','user_name','time','request']

            for splitted in Split_log:
                if not splitted: continue
                In_split = splitted.split(' ')
                host = In_split[0]
                user_name = In_split[2]
                time_temp = re.findall('\[.*?\]',splitted)
                time1 = time_temp[0][1:len(time_temp[0])-1]
                request_temp = re.findall('\".*?\"',splitted)
                request = request_temp[0][1:len(request_temp[0])-1]
                listdata = list()
                listdata.append(host)
                listdata.append(user_name)
                listdata.append(time1)
                listdata.append(request)

                Merged_list_single = merge_lists(list_header, listdata)
                Merged_list_single = dict(Merged_list_single)
                Main_list.append(Merged_list_single)
                listdata.clear()
    return Main_list
    
    # YOUR CODE HERE
    raise NotImplementedError()
assert len(logs()) == 979

one_item={'host': '172.16.17.32',
  'user_name': 'feest6811',
  'time': '21/Jun/2019:15:45:24 -0700',
  'request': 'POST /incentivize HTTP/1.1'}
assert one_item in logs(), "Sorry, this item should be in the log results, check your formating"<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21024167652526618, 'fraction_numerical': 0.026026702720973467, 'mean_word_length': 3.486732373009856, 'pattern_counts': {'":': 4, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '544604', 'license': 'MIT', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1633, 'n_words': 518, 'path': '1_Introduction to Data Science in Python/Assignment 1/assignment1.ipynb', 'repo_name': 'pruthvirajg/Applied-Data-Science-with-Python--UMICH', 'size': '5947'}