python练习之读取文件,list,hash

#    ['A', 36],
#    ['B', 85],
#    ['C', 15],
#    ['B', 65],
#    ['B', 52],
#    ['A', 89]

dataFile = open("data.txt")
l = []
for line in dataFile:
    if line.strip():
        l.append(line.strip().split(','))
dataFile.close()

res = {}
for item in l:
    k = item[0]
    if not res.has_key(k):
        res[item[0]] = []
    res[item[0]].append(item[1])

print res

你可能感兴趣的:(c,python,list)