If you are not working with a ridiculously large file, you may not use .strip() at all. If you read the entire file as a line using .read() , then do .splitlines() on that line.
Here is an example. I commented on your code where I made a difference. I changed the example so as not to use a slice in exchange for an explicit assignment of variables.
subject_dic = {} inputFile = open(filename) # Turn "line1\nline2\n" into ['line1', 'line2'] inputData = inputFile.read().splitlines() #for line in inputFile: for line in inputData: #split_line = string.split(line, ',') #subject_dic[split_line[0]] = tuple(split_line[1:3]) mykey, myval1, myval2 = line.split(',') # Strings always have .split() subject_dic[mykey] = (myval1, myval2) # Explicit tuple assignment print subject_dic
Outputs:
{'6.00': ('10', '1'), '6.01': ('5', '4'), '6.02': ('5', '6'), '6.03': ('2', '9'), '6.04': ('1', '2'), '6.05': ('1', '18'), '6.06': ('5', '19'), '6.07': ('2', '10'), '6.08': ('1', '10'), '6.09': ('3', '7'), '6.10': ('8', '18'), '6.11': ('6', '8'), '6.12': ('6', '3'), '6.13': ('9', '16'), '6.14': ('10', '8'), '6.15': ('10', '6'), '6.16': ('6', '9'), '6.17': ('9', '3'), '6.18': ('10', '4'), '6.19': ('8', '19')}