我的程序将导入由具有最大的文本的15行用户创建的文件中它(下面的例子)列表过滤
#ID #value1 # value2
445 4 9000
787 2 4525
405 4 3352
415 1 2854
455 2 5500
ř 程序然后过滤所有具有#VALUE 1线大于2和#值2大于3000并打印出他们的#ID,忽略其余部分。
这是我迄今所做
filename = ('input.txt')
infile = open(filename, 'r')
list_id = []
list_value1 = []
list_value2 = []
masterlist = []
for line in infile:
id, value1, value2 = line.split()
list_id.append(id)
list_value1.append(value1)
list_value2.append(value2)
masterlist.append(list_id)
masterlist.append(list_value1)
masterlist.append(list_value2)
#filtering part
sort = [i for i in masterlist[1] if i > 2 ] and [p for p in masterlist[2] if p > 3000]
#do something here to print out the ID of the filtered lines
这是过滤,而不是排序。 –
哦,是的,你是对的。 – user2958069
并且'和'不会加入这两个列表。 –