Untitled
unknown
python
2 years ago
606 B
6
Indexable
# Input optionRule = '{1069} AND ({1070} OR {1071} OR {1072}) AND {1244} AND ({1245} OR {1339})' optionRule = optionRule.replace('{', '').replace('}', '') dic_and = dict() lst_and = list() for option in optionRule.split('AND'): a = option.strip().replace('(', '').replace(')', '') dic_or = dict() if 'OR' in a: lst_or = list() for b in a.split('OR'): lst_or.append(int(b.strip())) dic_or['OR'] = lst_or lst_and.append(dic_or) else: lst_and.append(int(a.strip())) dic_and['AND'] = lst_and import json print(json.dumps(dic_and, indent=4))
Editor is loading...