所以我有一个清单: 有一个 txt 文件,我根据换行符将文本分成不同的部分 splittext = text_nonum.split(' ' * 6)
并创建了一个名为 spl_list2 的新列表
当我 print(type(spl_list2)) 时,它显示
请帮忙并提前致谢!
#to get rid of all empty elements in the list: ('')
splittext = text_nonum.split('\n' * 6)
spl_list = []
for i in splittext:
if i not in (''):
spl.append(i)
#then eliminate all spaces
spl_list2 = []
for m in spl_list:
m = m.strip()
spl_list2.append(m)
print(type(spl_list2))
assert type(spl_list2) == list
运行代码时的预期:::
####spl_list2 是一个长文本,如下所示:
#当打印(spl_list2)时
[“成功。 成功被认为是最甜蜜的 那些从未成功过的人……”、“……”、“…………”、“ 我带你去那里,—— 陆地,嗬!永恒! 终于上岸了!”]
####(“.....”是诗句)
##例如,当我打印(spl_list2[5])时,它输出:
A bone has obligations,
A being has the same;
A marrowless assembly
Is culpabler than shame.
But how shall finished creatures
A function fresh obtain? --
Old Nicodemus' phantom
Confronting us again!
运行它给出的所有内容时:
<class 'list'>
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In[74], line 19
15 spl_list2.append(m)
17 print(type(spl_list2))
---> 19 assert type(spl_list2) == list
AssertionError: