Created
June 6, 2014 16:48
-
-
Save sapamja/7906be5ddc3d22d40609 to your computer and use it in GitHub Desktop.
Check multiple key exists in dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> dic = { 1 : 'a', 2: 'b' } | |
| >>> set(dic) | |
| set([1, 2]) | |
| # Check if any key exists: | |
| >>> set([1,2]) <= set(dic) | |
| True | |
| >>> set([1]) <= set(dic) | |
| True | |
| >>> set([3,4]) <= set(dic) | |
| False | |
| # Check all the key in the list exists in the dictionary: | |
| >>> set([3,4]) == set(dic) | |
| False | |
| >>> set([1,2]) == set(dic) | |
| True | |
| >>> set([1,2]) == set(dic) | |
| True | |
| >>> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment