我有名字ids.txt
文件还与名在ids.txt
文件中,我们看到文件names.txt
如何加入相应的数组中的元素在Python
:
23
422
5123
642
8743
的names.txt
文件的内容:
jon1
jon2
jon3
jon4
jon5
我想这样的排序是:
23 jon1
422 jon2
5123 jon3
642 jon4
8743 jon5;
当它的排序的最后一个设置像这样
8743 jon5;
我在做什么是:
IDs = file("IDs.txt").read().splitlines()
names = file("names-specialitys.txt").read().splitlines()
for i in IDs:
for n in names:
print i, n
但它的打印这样的:
23 jon1
422 jon1
5123 jon1
642 jon1
8743 jon1
23 jon2
...等
'zip'这两个列表。 –
在你的问题中,你说'排序',但是列表[22,422,5123,642,...]没有排序(无论如何都是升序或降序)。我认为你的意思是你想将两个列表中的项目组合在一起。 – Alasdair