A command-line tool that determines how many "degrees of separation" exist between two actors, based on the movies theyβve co-starred in.
This program models the famous Six Degrees of Kevin Bacon game, which posits that any two actors can be connected through six or fewer mutual film roles. Using breadth-first search (BFS), this tool finds the shortest connection path between any two actors via shared movie appearances.
$ python degrees.py large
Loading data...
Data loaded.
Name: Emma Watson
Name: Jennifer Lawrence
3 degrees of separation.
1: Emma Watson and Brendan Gleeson starred in Harry Potter and the Order of the Phoenix
2: Brendan Gleeson and Michael Fassbender starred in Trespass Against Us
3: Michael Fassbender and Jennifer Lawrence starred in X-Men: First Class
The program supports two datasets: small and large. Each dataset folder includes the following files:
people.csv: Contains actor information
id, name, birth
movies.csv: Contains movie information
id, title, year
stars.csv: Maps actors to the movies they starred in
person_id, movie_id
Example
If stars.csv contains:
102,104257
Then Kevin Bacon (ID 102) starred in A Few Good Men (ID 104257), which can be confirmed using the corresponding entries in people.csv and movies.csv.
The program constructs a graph where:
- Nodes represent actors
- Edges represent co-starring in a film
It performs BFS to explore the shortest path between two actors:
- Each level of search expands to all co-stars of the current actor
- Paths are tracked to return the list of actors and movies involved
Prerequisites
- Python 3.x
Running the Program
$ python degrees.py [dataset]
Example:
$ python degrees.py small
Youβll be prompted to enter two actor names, and the program will return the shortest connection between them.
βββ degrees.py
βββ util.py
βββ small/
β βββ people.csv
β βββ movies.csv
β βββ stars.csv
βββ large/
β βββ people.csv
β βββ movies.csv
β βββ stars.csv
- Accurate actor lookup with name disambiguation
- Fast search using breadth-first algorithm
- Scalable to large datasets
- Modular and easy to read codebase
- Kevin Bacon β Tom Hanks
- Emma Watson β Daniel Radcliffe
- Chris Pratt β Zoe Saldana