码迷,mamicode.com
首页 > 编程语言 > 详细

Python 分解带括号的字符串

时间:2016-05-13 23:28:20      阅读:1029      评论:0      收藏:0      [点我收藏+]

标签:

__author__ = Alex
import re;
str_list = []
def fetch(ci,li,str):
    for k in range(len(ci)-1):
        if ci[k] > ci[k+1]:
            print(("li[k] = %s,li[k+1] = %s")%(li[k],li[k+1]))
            s = str[li[k]:li[k+1]+1]
            str_list.append(s)
            print (str_list)
            del ci[k]
            del ci[k]
            del li[k]
            del li[k]
            return str_list

str = "1 - 2*(17-(60-30+(-40*2/5)*9-2*5/3+7/3*99/4*2998+10*568/14))-(-4*3)/(16-3*2)"
count = 0
i_list = []
count_list = []
for i in range(len(str)):
    if str[i] == (:
        # print ("i= ",i)
        count +=1
        i_list.append(i)
        count_list.append(count)
        print (("i = %s ,count = %s ")%(i,count))
    if str[i] == ):
        # print ("i= ",i)
        count -=1
        i_list.append(i)
        count_list.append(count)
        print (("i = %s ,count = %s ")%(i,count))
print (i_list)
print (count_list)

while len(count_list)>0:
    symbols_list = fetch(count_list,i_list,str)

# print (int(symbols_list[1]))


Python 分解带括号的字符串

标签:

原文地址:http://www.cnblogs.com/python-study/p/5491376.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!