unit_cost = open(“/ Users / amit / Downloads / NetworkDesign 3 / small_example / unit_tran_cost.txt”,“r”) ucost = unit_cost.read
unitcostlist_of_lists = []
对于unit_cost中的行:
inner_list = [i for i in line.split()]
unitcostlist_of_lists.append(inner_list)
unitcostlist_of_lists
输出是:[['4,16,8,4'],['6,6,6,9'],['12,15,7,8']]
所需的输出是:[['4','16','8','4'],['6','6','6','9'],['12',' 15' , '7', '8']]
我打开的文件如下:
4,16,8,4
6,6,6,9
12,15,7,8
答案 0 :(得分:0)
我认为你只需要机会split()
到split(",")
,即
inner_list = [i for i in line.split(",")]
unitcostlist_of_lists.append(inner_list)
应该做的伎俩。