Skip to content

Instantly share code, notes, and snippets.

@sapamja
Created June 6, 2014 16:48
Show Gist options
  • Save sapamja/7906be5ddc3d22d40609 to your computer and use it in GitHub Desktop.
Save sapamja/7906be5ddc3d22d40609 to your computer and use it in GitHub Desktop.
Check multiple key exists in dictionary
>>> 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