Written by Erin McCoy, Katie Creel, Diana Navas, Juliette Woodrow, and Elyse Cornwall. Inspired by “The Next Bechdel Test”.
Let's revisit a problem from last section: we have a list of temperatures temps_f
in Fahrenheit,
and we want to produce a list temps_c
of those temperatures in Celsius.
temps_f = [45.7, 55.3, 62.1, 75.4, 32.0, 0.0, 100.0]
Last section, we saw how to
do this with map
. Now, write a list comprehension to create the list temps_c
.
Suppose we have a list of tuples representing movies, for example:
movies = [('alien', 8, 1), ('titanic', 6, 9), ('parasite', 10, 6), ('caddyshack', 4, 5)]
The first element of each movie tuple is the movie name, the second element is the overall score, and the
third element is the "date score" (how appropriate the movie is for a date). Write list comprehensions to
do the following, given some list movies
like the one above.
Named for Alison Bechdel, the Bechdel Test seeks to analyze the representation of women in fictional media. To pass the Bechdel Test, a film must:
The popularity of the Bechdel Test has inspired others to create their own tests measuring other inequities in media. Here are a few examples:
For more information about Bechdel and definitions of other tests, take a look at “The Next Bechdel Test” article.
In this section, you will use your nested data structure and matplotlib skills to build your very own data visualization program. You will use a dataset consisting of about 50 movies, along with which tests each movie passes and fails. Your goal is to build a piece of software that helps you investigate representation and bias in movies.
This problem is a natural extension of the interesting ethical topics that we have talked about in CS106A so far this quarter. Our hope is that by introducing these topics early in your computer science education, we can help the next generation of computer scientists - which now includes you! - be mindful of the potential social implications of their work, and use their powerful skills to help others.
python3 -m pip install matplotlib
Movie,Bechdel,Peirce,Landau,Feldman,Villarreal,Hagen,Ko,Villalobos,Waithe,Koeze_Dottle,Uphold,White,Rees-Davies
Bad Moms,0,0,0,1,0,0,0,1,0,0,1,1,1
Hidden Figures,0,0,0,0,0,1,0,1,0,1,1,1,1
Independence Day: Resurgence,0,0,1,0,0,1,0,1,0,0,1,1,1
The first line of the file
tells us what each of the columns means. Each line that follows contains a movie name, followed by a
series of 0’s and 1’s that represent if a movie has passed a test (0), or failed (1). For example, "Bad Moms"
passes the Bechdel Test, but fails the Feldman test. We want to store this
data as a movie_data
dictionary where the key is a movie name, like "Bad Moms" and the value is a
list of the
tests it
fails and passes as integers. Here's an example of what our movie_data
dictionary might
look like:
{
'Bad Moms': [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1],
'Hidden Figures': [0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1],
'Independence Day: Resurgence': [0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1],
...
}
Implement the function,
read_file(filename)
which opens a text file like the one above and creates and returns a
movie_data
dictionary
as described above. You can print out what your movie_data
dictionary looks like by running
python3 bechdelgraphs.py -dict
Implement the function
plot_test(movie_data, test_name)
,
which
plots the total number of movies that passed and failed for a specific test,
using
a movie_data
dictionary just like the one from Milestone 2.
We've provided the line
test_index = TESTS.index(test_name)
to get the index of a given test name in our test list. For
example, test_index for "Bechdel" is 0, and test_index for "Feldman" is 3. From here, you'll total
all the passes and fails for this test_index across all the movies in movie_data
, adding to the
count
variables num_passed and num_failed that we provide for you.
Finally, you'll plot your data on a bar graph. Recall that you can use matplotlib to make a bar graph by providing a list of x and y values, and a color (or a list of colors):
x_vals = # some list of x values
y_vals = # some list of y values
plt.bar(x_vals, y_vals, color="green")
To test your function, type:
python3 bechdelgraphs.py -test Bechdel
Your plot might look something like the following:
Check out other tests by running python3 bechdelgraphs.py -test TestName
for any test name
shown in the data file. For example, how many movies in our dataset
pass the Villalobos Test?