0
我创建了三个文本文件,每个文本文件都有10个用逗号分隔的随机数字。然后我有一个Python程序,它接受用户的文本文件的名称,从文本文件中读取数字到列表中,然后对原始列表和排序列表进行排序和打印。删除数字列表中的“ n”
prompt = raw_input("Enter the name of the text file you want to open: ")
fileopen = open(prompt)
for line in fileopen:
numbers = line.split(",")
sortednumbers = sorted(numbers)
print numbers
print sortednumbers
但是,打印结果列表总是只包含一个值,该值附加在数字的末尾(例如99 \ n)。我注意到它始终是文本文件中的最后一个数字。我怎样才能让它显示没有“\ n”的文本文件中的数字?
你在编程语言是什么? – scunliffe 2014-09-25 18:25:04
闻起来像蟒蛇。 – 2014-09-25 18:42:16
我不明白算法列表和排序标签! – Lrrr 2014-09-25 18:44:12