我正在尝试列出姓名,按字母顺序排列并将它们打印到新列表中。这是我的代码:
names = []
newnames = []
with open("C:/names.txt", "r") as infile:
for row in infile.readlines():
name = row.split()
names.append(name)
for x in sorted(names):
newnames.append(x)
print newnames
f = open("C:/newnames.txt", "w")
f.write("\n".join(str(x) for x in newnames))
f.close()
我的问题是它打印得很好,除了括号:
['Bradley']
['Harold']
['Jackson']
['Lincoln']
['Mercury']
['Shane']
['Sharon']
['Sherry']
['Xavier']
['Zoolander']
我想要文本文件中没有括号或引号的列表