Last active
April 5, 2017 12:27
-
-
Save billykong/951372f802a04a4578da878ae4721655 to your computer and use it in GitHub Desktop.
Create dictionary from another dictionary with dictionary comprehension
This file contains 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
cookie = { | |
'domain': 'pythonscraping.com', | |
'httponly': False, | |
'name': 'has_js', | |
'path': '/', | |
'secure': False, | |
'value': '1' | |
} | |
keys = ['name', 'value', 'domain', 'path', 'expiry'] # 'expiry' is absent from the cookie dict | |
new_cookie = {k: cookie[k] for k in keys if k in cookie.keys()} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment