/ Published in: Python
Snippet to verify whether or not a key exists in a python dictionary.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
myFavoriteGhibliMoviesReleaseYearDict = { 'Whisper of the Heart' : '1995', 'Princess Mononoke' : '1997', 'Spirited Away' : '2001' } if 'Spirited Away' in myFavoriteGhibliMoviesReleaseYearDict: print('\'Spirited Away\' release year: ' + myFavoriteGhibliMoviesReleaseYearDict['Spirited Away']) else: print('\'Spirited Away\' release year not found.')