Supreme Court Cases

Ever wondered how searching a database really works? Let’s write a program in Python to replicate some of the very same functionality!

In a file called cases.py, implement a program in Python that prompts the user for a phrase and then outputs all of the Supreme Court cases which have that phrase in their name.

Demo

Before You Begin

Log into code.cs50.io, click on your terminal window, and execute cd by itself. You should find that your terminal window’s prompt resembles the below:

$

Next execute

mkdir cases

to make a folder called cases in your codespace.

Then execute

cd cases

to change directories into that folder. You should now see your terminal prompt as cases/ $. You can now execute

code cases.py

to make a file called cases.py where you’ll write your program. In that same folder, cases/, be sure to type

wget https://cdn.cs50.net/hls/2023/winter/labs/0/cases/cases.csv

to download the corresponding dataset of Supreme Court cases, a subset of the dataset from Washington University in St. Louis.

How to Test

Here’s how to test your code manually:

  • Run your program with python cases.py. Type Heller and press Enter. Your program should output:
    HELLER v. NEW YORK
    CITY OF LOS ANGELES et al. v. HELLER
    LEONARD HELLER, SECRETARY, KENTUCKY CABINET FOR HUMAN RESOURCES v. SAMUEL DOE, BY HIS MOTHER AND NEXT FRIEND, MARY DOE, et al.
    DISTRICT OF COLUMBIA v. HELLER
    WHOLE WOMAN'S HEALTH v. HELLERSTEDT
    
  • Run your program with python cases.py. Type Hodges and press Enter. Your program should output, among other cases:
    HODGES v. UNITED STATES
    ROSE, WARDEN v. HODGES et al.
    OBERGEFELL v. HODGES
    
  • Run your program with python cases.py. Type Gore and press Enter. Your program should output
    GORE v. UNITED STATES
    BMW OF NORTH AMERICA, INC. v. IRA GORE, JR.
    FEDERAL ELECTION COMMISSION v. JAMES E. AKINS, RICHARD CURTISS, PAUL FINDLEY, ROBERT J. HANKS, ANDREW KILLGORE, AND ORIN PARKER
    GEORGE W. BUSH AND RICHARD CHENEY v. ALBERT GORE, JR., et al.
    

Acknowledgements

Data courtesy of Washington University in St. Louis, licensed under CC BY-NC 3.0 US. Provided dataset is a subset of the original.