This is basic python script that parses a string and retrieves parameters and their values.
import re
link = "met_y=population&fdim_y=patientStatus:7&fdim_y=pregnant:1&scale_y=lin&ind_y=false&rdim=department&idim=department:9:2:4&idim=clinic:93301:91100:93401:41201:41100&ifdim=department&tstart=1190617200000&tend=1220511600000&ind=false&draft"
print link
filters = ''
matches = re.findall("\&?(?P<name>\w+)=(?P<value>(\w|:)+)\&?",link )
for match in matches:
name = match[0]
value = match[1]
selection = value.split(':')
filters = {}
print selection[0]
print selection[1:len(selection)]
filters[selection[0]] = selection[1:len(selection)]
print filters
The issue here is that the hashtable filters never gets these values. The output of this script is
{'false': []}
What am I doing wrong?
You’re recreating
filtersinside the loop:This line needs to be placed before the loop, not inside.
Another potential issue is that your input contains duplicate keys (
fdim_yandidim). As things stand, your code only keep the last value of each key.