Skip to content

Instantly share code, notes, and snippets.

@mdang
Last active December 24, 2021 12:02
Show Gist options
  • Save mdang/d82ab16ae5129c47a1ea9457b79ebf09 to your computer and use it in GitHub Desktop.
Save mdang/d82ab16ae5129c47a1ea9457b79ebf09 to your computer and use it in GitHub Desktop.
Exercise: Python IMDB (Starter)
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Dictionary of movies\n",
"\n",
"movies = [\n",
"{\n",
"\"name\": \"Usual Suspects\", \n",
"\"imdb\": 7.0,\n",
"\"category\": \"Thriller\"\n",
"},\n",
"{\n",
"\"name\": \"Hitman\",\n",
"\"imdb\": 6.3,\n",
"\"category\": \"Action\"\n",
"},\n",
"{\n",
"\"name\": \"Dark Knight\",\n",
"\"imdb\": 9.0,\n",
"\"category\": \"Adventure\"\n",
"},\n",
"{\n",
"\"name\": \"The Help\",\n",
"\"imdb\": 8.0,\n",
"\"category\": \"Drama\"\n",
"},\n",
"{\n",
"\"name\": \"The Choice\",\n",
"\"imdb\": 6.2,\n",
"\"category\": \"Romance\"\n",
"},\n",
"{\n",
"\"name\": \"Colonia\",\n",
"\"imdb\": 7.4,\n",
"\"category\": \"Romance\"\n",
"},\n",
"{\n",
"\"name\": \"Love\",\n",
"\"imdb\": 6.0,\n",
"\"category\": \"Romance\"\n",
"},\n",
"{\n",
"\"name\": \"Bride Wars\",\n",
"\"imdb\": 5.4,\n",
"\"category\": \"Romance\"\n",
"},\n",
"{\n",
"\"name\": \"AlphaJet\",\n",
"\"imdb\": 3.2,\n",
"\"category\": \"War\"\n",
"},\n",
"{\n",
"\"name\": \"Ringing Crime\",\n",
"\"imdb\": 4.0,\n",
"\"category\": \"Crime\"\n",
"},\n",
"{\n",
"\"name\": \"Joking muck\",\n",
"\"imdb\": 7.2,\n",
"\"category\": \"Comedy\"\n",
"},\n",
"{\n",
"\"name\": \"What is the name\",\n",
"\"imdb\": 9.2,\n",
"\"category\": \"Suspense\"\n",
"},\n",
"{\n",
"\"name\": \"Detective\",\n",
"\"imdb\": 7.0,\n",
"\"category\": \"Suspense\"\n",
"},\n",
"{\n",
"\"name\": \"Exam\",\n",
"\"imdb\": 4.2,\n",
"\"category\": \"Thriller\"\n",
"},\n",
"{\n",
"\"name\": \"We Two\",\n",
"\"imdb\": 7.2,\n",
"\"category\": \"Romance\"\n",
"}\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Write a function that takes a single movie and \n",
"# returns True if its IMDB score is above 5.5"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Write a function that returns a sublist of movies \n",
"# with an IMDB score above 5.5. "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Write a function that takes a category name and returns \n",
"# just those movies under that category."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Write a function that takes a list of movies and computes \n",
"# the average IMDB score."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Write a function that takes a category and computes \n",
"# the average IMDB score (HINT: reuse the function \n",
"# from question 2.)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@annamrajaiah
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment