Skip to content

Instantly share code, notes, and snippets.

@kennethreitz
Created February 12, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kennethreitz/90c79b1c98d850eed711 to your computer and use it in GitHub Desktop.
Save kennethreitz/90c79b1c98d850eed711 to your computer and use it in GitHub Desktop.
def dictify(s):
items = s.split()
for i, item in enumerate(items):
if ':' in item:
items[i] = item.split(':')
else:
items[i] = (item, True)
print dict(items)
s = 'foo bar:baz'
print dictify(s)
@kennethreitz
Copy link
Author

dict([i.split(':') if ':' in i else (i, True) for i in 'foo bar:baz'.split()])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment