<jupyter_start><jupyter_text>Exercise: Count Opinions per Author In the JSON case law data, each opinion has an `author` field.Complete the code below to count the number of opinions per author.You will need to browse the [data](https://api.case.law/v1/cases/?jurisdiction=ill&full_case=true&decision_date_min=2011-01-01&page_size=1"). a)<jupyter_code>import requests
import json

URL = "https://api.case.law/v1/cases/?jurisdiction=ill&full_case=true&decision_date_min=2011-01-01&page_size=20"
data = requests.get(URL).json()

author2count = {}

cases = data["results"]
for case in cases:
    print(case)<jupyter_output><empty_output><jupyter_text>b)<jupyter_code>import requests
import json

URL = "https://api.case.law/v1/cases/?jurisdiction=ill&full_case=true&decision_date_min=2011-01-01&page_size=20"
data = requests.get(URL).json()

author2count = {}

cases = data["results"]
for case in cases:
    casebody = case["casebody"]
    case_data = casebody["data"]
    opinions = case_data["opinions"]
    print(opinions)<jupyter_output><empty_output><jupyter_text>c)<jupyter_code>import requests
import json

URL = "https://api.case.law/v1/cases/?jurisdiction=ill&full_case=true&decision_date_min=2011-01-01&page_size=20"
data = requests.get(URL).json()

author2count = {}

cases = data["results"]
for case in cases:
    casebody = case["casebody"]
    case_data = casebody["data"]
    opinions = case_data["opinions"]
    for opinion in opinions:
        author = opinion["author"]
        print(author)<jupyter_output><empty_output><jupyter_text>d)<jupyter_code>import requests
import json

URL = "https://api.case.law/v1/cases/?jurisdiction=ill&full_case=true&decision_date_min=2011-01-01&page_size=20"
data = requests.get(URL).json()

author2count = {}

cases = data["results"]
for case in cases:
    casebody = case["casebody"]
    case_data = casebody["data"]
    opinions = case_data["opinions"]
    for opinion in opinions:
        author = opinion["author"]
        if author not in author2count:
            author2count[author] = 1<jupyter_output><empty_output><jupyter_text>e)<jupyter_code>import requests
import json

URL = "https://api.case.law/v1/cases/?jurisdiction=ill&full_case=true&decision_date_min=2011-01-01&page_size=20"
data = requests.get(URL).json()

author2count = {}

cases = data["results"]
for case in cases:
    casebody = case["casebody"]
    case_data = casebody["data"]
    opinions = case_data["opinions"]
    for opinion in opinions:
        author = opinion["author"]
        if author not in author2count:
            author2count[author] = 1
        else:
            author2count[author] += 1<jupyter_output><empty_output><jupyter_text>f)<jupyter_code>import requests
import json

URL = "https://api.case.law/v1/cases/?jurisdiction=ill&full_case=true&decision_date_min=2011-01-01&page_size=20"
data = requests.get(URL).json()

author2count = {}

cases = data["results"]
for case in cases:
    casebody = case["casebody"]
    case_data = casebody["data"]
    opinions = case_data["opinions"]
    for opinion in opinions:
        author = opinion["author"]
        if author not in author2count:
            author2count[author] = 1
        else:
            author2count[author] += 1

# Show results
print("\nNumber of opinions per author:")
for author in author2count:
    count = author2count[author]
    print(author, "wrote", count, "opinions")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13307984790874525, 'fraction_numerical': 0.028370868675051186, 'mean_word_length': 4.643564356435643, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '396448', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1146, 'n_words': 220, 'path': 'solutions/solutions_10.ipynb', 'repo_name': 'scriptotek/programming-for-librarians', 'size': '3419'}