fruit,apple
fruit,tomato
vegetable,carrot
fruit,pear
vegetable,celery
vegetable,cabbage
vegetable,cauliflower
fruit,banana
我想像这样将列表与水果和蔬菜分开
水果
apple
tomato
pear
banana
蔬菜
carrot
celery
cabbage
cauliflower
这是我到目前为止所做的代码
infile = open("hw16.txt","r")
lines = infile.readlines()
infile.close()
print lines
x = []
y = []
for i in range(0, len(lines)):
tokens = lines[i].rstrip('\n').split(",")
x.append(str(tokens[0]))
y.append(str(tokens[1]))
print x
print y
谢谢你