Question: Write a python that that uses regular expressions to extract all the CSE courses from a Computer Science Curriculum webpage It should basically be the
Write a python that that uses regular expressions to extract all the CSE courses from a Computer Science Curriculum webpage
It should basically be the Python equivalent of the following pipeline:
$ curl -sL URL \ | grep -Eo 'CSE [234][0-9]{4}' \ | sed -E -e 's/CSE 2.*/Sophomore/' -e 's/CSE 3.*/Junior/' -e 's/CSE 4.*/Senior/' \ | sort | uniq -c | sort -rn Skeleton:
import collections import re import requests # Globals URL = # Initialize a default dictionary with integer values counts = None # TODO: Make a HTTP request to URL response = None # TODO: Access text from response object data = None # TODO: Compile regular expression to match CSE courses (ie. CSE XXXXX) regex = None # TODO: Search through data using compiled regular expression and count up all # the courses per class year for course in re.findall(None, None): pass # TODO: Sort items in counts dictionary by value in reverse order and # display counts and class year for year, count in sorted(counts.items(), key=lambda p: p[1]): print(f'{count:>7} {year}')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
