#/usr/bin/env python
#-*-Coding:utf-8-*-
#思路: First find ' ('; corresponding ') ' to satisfy the index greater than ' (' and the leftmost index; Find an index list from ') ' to remove a
#以如下表达式为例
#1 +3+ ((5*5+6) +5) -6/3-(4+5)
A= ' 1+3+ ((5*5+6) +5) -6/3-(4+5) '
La=[]
Lb=[]
For I in range (Len (a)):
If a[i]== ' (':
La.append (i)
Elif a[i]== ') ':
Lb.append (i)
If Len (LA)!=len (LB):
Print ("Your expression is wrong with using symblic ' (' or ') ')
Else
Print ("LA:", Sorted (LA))
Print ("lb:", sorted (LB))
Print ("La|lb", Set (LA) |set (LB))
Couple1=dict.fromkeys (La,none)
Print (sorted (Couple1.items (), Key=lambda d:d [0],reverse=false])
For I in Sorted (Couple1.keys (), reverse=true):
For j in Sorted (lb):
If J>i:
Couple1[i]=j
Lb.remove (j)
Break
Print ("Delimited index fragment:", Sorted (Couple1.items (), Key=lambda d:d[0]))
Python implements parentheses grouping