我正在使用python开发基本的文本解析器(因为JavaScript显然是此类事情的噩梦)。我在检测数组中的括号时遇到问题。这是数据集的示例。
['0.0' '' '$15,448' '$15,114' '$48,966' '$47,338' '15,123' '11,705'
'43,160' '32,937' '30,571' '26,819' '92,126' '80,275' '3,441' '3,425'
'12,975' '11,903' '6,729' '5,844' '19,523' '16,708' '10,170' '9,269'
'32,498' '28,611' '20,401' '17,550' '59,628' '51,664' '4,316' '3,715'
'12,363' '10,793' '4,565' '4,335' '13,251' '12,709' '1,179' '1,208'
'3,460' '3,483' '10,341' '8,292' '30,554' '24,679' ',' '145' '349' '538'
'1,115' '10,486' '8,641' '31,092' '25,794' '1,677' '1,217' '5,039'
'18,096' '$' '8,809' '$7,424' '$26,053' '$' '7,698' '$1.15' '$0.96'
'$3.39' '$1.00' '$1.14' '$0.95' '$3.36' '$0.99' '7,672' '7,698' '7,679'
'7,706' '7,744' '7,794' '7,759' '7,798' '.' '3' '1' '31,' '31,' '2019'
'2018' '2019' '2018' '$8,809' '$7,424' '$26,053' '$7,698' ',' '33' '7'
'93' '106' '714' '1,016' '1,334' '2,182' '67' '255' '252' '508' '748'
'754' '989' '1,780' '$9,557' '$6,670' '$27,042' '$5,918' '.' '16' '.' '4'
'1']
此数组是从.txt文件创建的。读取.txt文件时,我可以测试文本是否带有括号。但是,由于某种原因,我无法遍历数组。
def removeExcess():
global numbers
for num in numbers:
if(num != ')' or num != '('):
print(num)