Skip to content

Instantly share code, notes, and snippets.

@devnull255
Created October 6, 2014 12:57
Show Gist options
  • Save devnull255/d040b643d43add946c04 to your computer and use it in GitHub Desktop.
Save devnull255/d040b643d43add946c04 to your computer and use it in GitHub Desktop.
Return a dictionary from list of key=value strings
def parse_keywords(keywords):
"""
Returns a dictionary for valid key=value strings
"""
d = {}
try:
d = dict([x.split('=',1) for x in keywords])
except ValueError,e:
for kw in keywords:
if '=' not in kw:
print "Keyword: %s is invalid" % kw
print "All keywords should be formatted as key=value."
return d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment