有一个代码:拆分内部的Python
def readData():
file = open('data.txt', 'r')
listing = []
for line in file:
print(line.split())
depart = line.split()
m = [line.strip()]
listing.append(m)
file.close()
return listing
def display():
depart = readData()
poorest = []
if int(depart[1]) <= int(depart[2])+int(depart[3]):
poorest.append(depart[0])
print(poorest)
的 '离开' 输出会产生这样的:
[['Ladies 250 184 196'], ['Gentlemen 167 321 459'], ['Toys \t180 150 210'], ['Beauty\t450 280 320'], ['Technology\t169 320 279'], ['Home\t120 58 45'], ['Appliances\t210 130 67'], ['Food\t180 45 89'], ['Shoes\t260 100 210'], ['Children 179 50 80']]
但我需要产生这样的:
['Ladies', '250', '184, '196']
每一个。我应该如何改变第二个功能?
试试这个,而不是'poorest.append(depart [0] .split())'在这里你分裂给定的字符串在空间 – The6thSense