Jul-05-2018, 10:23 AM
you can reverse the order of the dictionary
example:
example:
data = [('Genres','Action'), ('Adventure','Action'), ('Adventure', 'Animation'), ('Adventure', 'Animation'), ('Comedy', 'Drama'), ('Action','Adventure'), ('Fantasy', 'Science Fiction')] mc_dict = dict((y, x) for x, y in data) print(mc_dict)gives you:
Output:{'Action': 'Adventure', 'Animation': 'Adventure', 'Drama': 'Comedy', 'Adventure': 'Action', 'Science Fiction': 'Fantasy'}