Posted By

denakitan on 09/30/11


Tagged

python key exists dictionary verification Verify existence dictionaries


Versions (?)

Python - Dictionary - Does key exist?


 / Published in: Python
 

Snippet to verify whether or not a key exists in a python dictionary.

  1. myFavoriteGhibliMoviesReleaseYearDict = {
  2. 'Whisper of the Heart' : '1995',
  3. 'Princess Mononoke' : '1997',
  4. 'Spirited Away' : '2001'
  5. }
  6.  
  7. if 'Spirited Away' in myFavoriteGhibliMoviesReleaseYearDict:
  8. print('\'Spirited Away\' release year: ' + myFavoriteGhibliMoviesReleaseYearDict['Spirited Away'])
  9. else:
  10. print('\'Spirited Away\' release year not found.')

Report this snippet  

You need to login to post a comment.