【发布时间】:2021-10-22 14:44:42
【问题描述】:
我应该得到合并的文本文件。我有一个 merge_txt 函数,它需要列表和文件名,但我得到了一个要合并的大文件列表。
我的大名单如下。它包含五个文件的路径,应该从 14 个不同的文件创建。
data = [
{'fn': '1_0001_01.txt', 'file': '0001.txt'},
{'fn': '1_0001_02.txt', 'file': '0001.txt'},
{'fn': '1_0001_03.txt', 'file': '0001.txt'},
{'fn': '1_0002_01.txt', 'file': '0002.txt'},
{'fn': '1_0002_02.txt', 'file': '0002.txt'},
{'fn': '1_0003_01.txt', 'file': '0003.txt'},
{'fn': '1_0003_02.txt', 'file': '0003.txt'},
{'fn': '1_0003_03.txt', 'file': '0003.txt'},
{'fn': '1_0004_01.txt', 'file': '0004.txt'},
{'fn': '1_0004_02.txt', 'file': '0004.txt'},
{'fn': '1_0004_03.txt', 'file': '0004.txt'}
{'fn': '1_0005_01.txt', 'file': '0005.txt'},
{'fn': '1_0005_02.txt', 'file': '0005.txt'},
{'fn': '1_0005_03.txt', 'file': '0005.txt'}
]
我试图了解如何迭代列表以获得新列表和文件名?
这样的列表应该被迭代。
lst = ['1_0001_01.txt', '1_0001_02.txt', '1_0001_03.txt']
这个列表应该交给merge_txt函数:
merge_txt(lst, '0001.txt')
有什么想法吗?我还没有想出任何解决方案。
【问题讨论】:
标签: python python-3.x list append