jeudi 18 février 2021

Only return unique element in python

I have run into a problem with my Python code. I am creating a movie filter after i scrapped IMDB for certain movies. However, the problem is that movies with multiple genres will show up identically in my movie_filter. So my code is following:

    def create_movies_drop_down(self):
        movies = []

        if "genres" in self.mappingQuery:
            mapping = [row for row in dataLakeDB["nordisk-film-movie-mapping"].find(dict(genres = self.mappingQuery["genres"]))]
        else:
            mapping = [row for row in dataLakeDB["nordisk-film-movie-mapping"].find()]
        for row in mapping:
            if row["title"] not in movies:
                movies.append(dict(movie = row["title"][0].upper()+row["title"][1:],
                                    imdbPageID = row["imdbPageID"]))
        return movies

Now i.e because the movie "DRUK" has the genres "Comende and drama" it will show up 2 times with the same title and imdb page ID. I have tried with multiple arguments, but can't seem to solve the specific reason why this happens. Can anyone help here?

Edit: The mapping for 1 movie is like this: [{'_id': '6028139039cba4ae2722f8d9', 'castList': '[Rosa Salazar, Christoph Waltz, Jennifer Connelly, Mahershala Ali, Ed Skrein]', 'clientID': 'FILM', 'dcmCampaignID': [''], 'director': 'Robert Rodriguez', 'dv360InsertionOrderID': ['7675053', '7675055', '7675065', '768 3006', '7863461'], 'genres': ['action', 'adventure', 'sci-fi'], 'imdbPageID': '0437086', 'imdbPageURL': 'https://ift.tt/2S3Mqw9', 'imdbRating': '7.3', 'marathonCountryID': 'PMDK', 'posterURL': 'https://ift.tt/3prqqug NTYzLTllM2UtZWY5ZTk0NmYwYzIyXkEyXkFqcGdeQXVyMzgxODM4NjM@.V1_UX182_CR0,0,182,268_AL.jpg', 'title': 'alita: battle angel\xa0(2019)'}

Aucun commentaire:

Enregistrer un commentaire