在python中以特殊格式打印文件中的列表
我有一个很大的列表列表,例如:
X = [['a','b','c','d','e','f'],['c','f','r'],['r','h','l','m'],['v'],['g','j']]
每个内部列表都是一个句子,这些列表的成员实际上是这个句子的单词。我想将此列表写入一个文件中,以便每个句子(内部列表)位于单独的文件中文件中的行,每行都有一个数字,对应于大 this 中这个内部列表(句子)的位置。在上述情况下。我希望输出看起来像这样:
1. a b c d e f
2. c f r
3. r h l m
4.v
5.g j
我需要将它们以这种格式写入“文本”文件中。谁能建议我用 python 编写它的代码? 谢谢
I have a large list of lists like:
X = [['a','b','c','d','e','f'],['c','f','r'],['r','h','l','m'],['v'],['g','j']]
each inner list is a sentence and the members of these lists are actually the word of this sentences.I want to write this list in a file such that each sentence(inner list) is in a separate line in the file, and each line has a number corresponding to the placement of this inner list(sentence) in the large this. In the case above. I want the output to look like this:
1. a b c d e f
2. c f r
3. r h l m
4.v
5.g j
I need them to be written in this format in a "text" file. Can anyone suggest me a code for it in python?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)