Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何删除文本的前10个单词?_Python_Python 3.x_Word_Remove_Txt - Fatal编程技术网

Python 如何删除文本的前10个单词?

Python 如何删除文本的前10个单词?,python,python-3.x,word,remove,txt,Python,Python 3.x,Word,Remove,Txt,我有一个txt文件,里面有一首Gibrán Halil Gibrán的诗,我必须从中删除前10个单词,可能还有一张地图,然后删除,但我不能把它放在一起。我用pop()试过这个。但我不知道该怎么做 for word in prophet: if word is [0]: prophet.pop[0] if word is [1]: prophet.pop[1] print(prophet) 请在此处找到一个示例: >>

我有一个txt文件,里面有一首Gibrán Halil Gibrán的诗,我必须从中删除前10个单词,可能还有一张地图,然后删除,但我不能把它放在一起。我用pop()试过这个。但我不知道该怎么做

for word in prophet:
    if word is [0]:
        prophet.pop[0]
    if word is [1]:
        prophet.pop[1]
        
print(prophet)
请在此处找到一个示例:

>>> text = "I have a txt file with a poem by Gibrán Halil Gibrán, from where I have to delete the first 10 words, probably with a map and delete, but I can't put it together. I tried this with pop (). But i don't have idea about how can i doit."
>>> text = ' '.join(text.split()[10:])
>>> text
"Halil Gibrán, from where I have to delete the first 10 words, probably with a map and delete, but I can't put it together. I tried this with pop (). But i don't have idea about how can i doit."

调用以下函数以删除前10个字:

def删除单词(文本):
words=text.split()
return“.join(单词[10:])
例如,整个脚本可能看起来像:

打开(“file.txt”)作为f:
text=f.read()
text=删除单词(text)
打开(“new_file.txt”、“w”)作为f:
f、 书写(文本)

您可以简单地使用
拆分方法:

s=“a bc d ef gh i jk l m p q r s”
ans=s.split(“,10)[1]
打印(ans)#给出“q r s”

什么是先知
?是列表还是字符串?另外,您认为
单词[0]
是什么意思?