fork(1) download
  1. import re
  2. filter_string = "(#1 AND #12) OR #10"
  3. filters_array = [(1,"something"),(10,"something_another"),(12,"another_something")]
  4. dt = dict(filters_array)
  5. filter_string = re.sub(r'#([0-9]+)', lambda x: dt[int(x.group(1))] if int(x.group(1)) in dt else x.group(), filter_string)
  6. print(filter_string)
Success #stdin #stdout 0.01s 23352KB
stdin
Standard input is empty
stdout
(something AND another_something) OR something_another