Skip to content

Instantly share code, notes, and snippets.

@tierpod
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tierpod/e6d651a0b7d1ae45a6a3 to your computer and use it in GitHub Desktop.
Save tierpod/e6d651a0b7d1ae45a6a3 to your computer and use it in GitHub Desktop.
python docopt arguments normalize: lowercase, remove '-'
'''
args: {'--append': True, 'FILE1': 'test', 'normal': 'normal'}
cfg: {'append': True, 'file1': 'test', 'normal': 'normal'}
'''
# simple way
cfg = {}
for arg in args:
cfg[arg.lower().replace('-','')] = args[arg]
# list comprehension way
cfg = {k.lower().replace('-',''): v for (k, v) in args.iteritems()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment