I'm making a Web Application about movies and using IMDb's API. Here's the JSON result:

"title":"The Shawshank Redemption",
"fullTitle":"The Shawshank Redemption (1994)",
"crew":"Frank Darabont (dir.), Tim Robbins, Morgan Freeman",
"title":"The Godfather",
"fullTitle":"The Godfather (1972)",
"crew":"Francis Ford Coppola (dir.), Marlon Brando, Al Pacino",
"fullTitle":"Sunrise (1927)",
"crew":"F.W. Murnau (dir.), George O'Brien, Janet Gaynor",

As you can see, this is a list of dicts inside an "items" dict. Since this is the top250 movies, I'm getting all of this data and I only want the top10. Is there a way to do this?

1 Answer 1


I'm getting otherwise related errors, so I can't know for sure, but I think I figured it out. All I need from the data is the name of the top10 movies to use others API requests and get additional info, so I did this:

def top_ten_movies():
    api_key = os.environ.get("API_KEY")
        url = f"https://imdb-api.com/en/API/Top250Movies/{api_key}"
        response = requests.get(url)

    except requests.RequestException:
        return None

        movies = response.json()
        y = movies["items"]

        for i in range(len(y)):
            while i < 10:
                return {
                    "name": y[i]["title"],

    except requests.RequestException:
        return None

If you see some mistake or room for improvement, feel free to tell me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .