Python-以制表符分隔文件的嵌套列表? [英] Python - Nested List to Tab Delimited File?

查看:177
本文介绍了Python-以制表符分隔文件的嵌套列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含约30,000个子列表的嵌套列表,每个子列表都有三个条目,例如,

I have a nested list comprising ~30,000 sub-lists, each with three entries, e.g.,

nested_list = [['x', 'y', 'z'], ['a', 'b', 'c']].

我希望创建一个函数,以便将此数据结构输出为制表符分隔格式,例如

I wish to create a function in order to output this data construct into a tab delimited format, e.g.,

x    y    z
a    b    c

任何帮助都将不胜感激!

Any help greatly appreciated!

预先感谢, Seafoid.

Thanks in advance, Seafoid.

推荐答案

with open('fname', 'w') as file:
    file.writelines('\t'.join(i) + '\n' for i in nested_list)

这篇关于Python-以制表符分隔文件的嵌套列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆