![](/img/trans.png)
[英](Pig-Latin converter read from .txt file) How to split contents of file into lines AND word by word? Python
[英]How to read word(or character) on txt file from the last word to the first word in python?
示例:我有一個文件:
filename1 =“我是學生”(在filename1中有我是學生)
f = open(filename1)
string = f.read()
spl = re.split('\s|(?<!\d)[,.](?!\d)',string)
f.close
print spl將會顯示:我是學生,但我需要結果,因為[學生是我]請您回答我...預先感謝。
str=['im a student','im a teacher']
list=[]
for x in str:
new=""
for y in [x for x in reversed(x.split())]:
new+=y
new+=' '
list.append(new)
print list // ['student a im ', 'teacher a im ']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.