Py学习  »  Python

在python中如何将一个文本字符串拆分为两列

Julie • 5 年前 • 1455 次点击  

我正在努力将一个文件文本的字符串分成两个独立的列。 在我把文本分成句子之后

for s in sentences:
    row = s.strip()            
    print(row)

它在同一列中提供此输出:

['1'
 "It is hands-down the best sporting museum in Australia
The kids (and dad) loved the interactive sports section
The amount of Olympic memorabilia was outstanding    
Don't miss going to this iconic venue."]
['2'
 "...
  ..."]

预期产出:

No     sentences
1     It is hands-down the best sporting museum in Australia
1     The kids (and dad) loved the interactive sports section
1     The amount of Olympic memorabilia was outstanding    
1     Don't miss going to this iconic venue.
2     ...
2     ...

任何人有任何想法,请帮忙!

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/44671
 
1455 次点击  
文章 [ 1 ]  |  最新文章 5 年前
U10-Forward
Reply   •   1 楼
U10-Forward    6 年前

听起来像是 sentences 例如:

sentences=[['1','foobar'],['2','blahblah']]

然后尝试:

print('\n'.join(['\t'.join(i) for i in sentences]))