我有这样的文字:
text = ["A/abc","B/abd","C/abc","D/xyz"]
我想要的输出是
mylist1 = ["A","C"]
mylist2 = ["B"]
mylist3 = ["D"]
我正在寻找的唯一标签是“/abc”和“/abd”
现在我拥有的是:
def searchWord(segment):
word_tag = segment.split('/')
if re.finditer('ab',word_tag[1]):
if re.finditer('abc',word_tag[1]):
letter = word_tag[0]
mylist1 = letter
else:
letter = word_tag[0]
mylist2 = letter
else:
letter = word_tag[0]
mylist3 = letter
return mylist1
return mylist2
return mylist3
mylist1,mylist2,mylist3 = [searchWord(segment) for segment in text]
它似乎工作正常,但抛出异常:
ValueError: too many values to unpack.
我的“文本”列表相当大,这可能是问题吗?在为此过程构建功能之前,我没有这个问题。
谢谢!