While learning about python, I came upon this code, which takes a text file, splits each line into an array, and inserts it into a custom dictionary, where the array[0] is the key and array[1] is the value:
my_dict = {}
infile = open("file.txt")
for line in infile:
#line = line.strip()
#parts = [p.strip() for p in line.split("\t")]
parts = [p for p in line.split("\t")]
my_dict[parts[0]] = parts[1]
print line
for key in my_dict:
print "key: " + key + "\t" + "value " + my_dict[key]
I ran the program with the commented lines off and on and I got the same result. (of course replacing the second commented line with the line below it).It seems to me that doing a strip() is optional. Is it better practice to leave it in?