【发布时间】:2020-01-05 01:36:19
【问题描述】:
我有一个列表列表,我正在尝试删除所有非字母字符。
我尝试使用isalpha()
data = [
['we', '\n\n', 'will', 'pray', 'and', 'hope', 'for', 'the', 'best'],
['though', '10/3/2011', 'it', 'may', 'not', '\n\n', 'make', 'landfall', 'all', 'week', '2 000 €', 'if', 'it', 'follows', 'that', '•', 'track'],
['heavy', 'rains', 'capable', 'of', 'producing', 'life threatening', 'flash', '•', 'floods', '\n\n', 'are', 'possible'],
]
new_data = ''.join([i for i in data if i.isalpha()])
预期输出:
['we will pray and hope for the best',
'though it may not make landfall all week if it follows that track',
'heavy rains capable of producing life threatening flash floods are possible']
我的输出:
AttributeError: 'list' object has no attribute 'isalpha'
【问题讨论】: