怎么删去列表的括号啊不理解

img

img


他这个输出有括号的 怎么弄没啊

去括号最简单的就是解包操作,你上面最后的输出,赋值给a,b 两个值,再输出就得了,

如:
a,b=items[i],
print(a,b)

这个不采纳就没谁了。。。

print(items[i].replace('(','').replace(')',''))

觉得有用的话采纳一下哈


# -*- coding:utf-8 -*-

import jieba
import re
# text=open('十四五规划纲要.txt','r',encoding='utf-8').read()
text="""('发展',189)
('建设',119)
('体系',90)
('完善',82)
('加强',79)"""

text = re.sub('\(','',text)   #都是英文版的括号
text = re.sub('\)','',text)
print(text)

words= jieba.lcut(text)
counts={}
for word in words:
    if len(word) ==1:
        continue
    else:
        counts[word]=counts.get(word,0)+1
items= list(counts.items())
items.sort(key=lambda x:x[1],reverse=True)
print(items)
for i in range(30):
    print(items[i])