Skip to content

Instantly share code, notes, and snippets.

@jvmsangkal
Created January 19, 2016 10:27
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 jvmsangkal/5fba446639bb8b049229 to your computer and use it in GitHub Desktop.
Save jvmsangkal/5fba446639bb8b049229 to your computer and use it in GitHub Desktop.
a = '12.5%WW|-US CA'.split('|')
general = []
for b in a:
c = {
'type': 'include',
'ratio': 100
}
b = b.strip()
if b[0] == '-':
c['type'] = 'exclude'
b = b[1:]
elif '%' in b:
d = b.split('%')
c['ratio'] = float(d[0])
b = d[1]
if b == 'WW':
c['type'] = 'exclude'
b = ''
c['territories'] = b.split()
general.append(c)
print(general)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment