python 2.7 - Creating a set of Unique Values from Dictionary effciiently -


i new python programming. have dictionary of objects queried mongodb. document contains movie id , relevant tweets regarding movie. movie_ids repeating , wanted create set of unique movie_ids . current code wrote follows:

client = mongoclient()      discovermovies = client['discovermovies'] tweets = discovermovies.tweetdbs.find() unique_movie = set() tweet in tweets:      unique_movie.add(tweet.get("movie_id")) movie in unique_movie:      print(movie) 

my question , there more efficient way achieve same, i.e getting unique set dictionary dictionary contains other key value pairs well?

thanks sourav

given tweet dictionary, set(tweet.values()) efficient can get.

a general example:

print set({'a': 1, 'b': 1, 'c': 2}.values()) # {1, 2} 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -