So I have a data.txt
file that holds information about a car:
CAR|PRICE|RPM
TOYOTA|21,000|3,600
HONDA|19,000|4,000
And by passing this data file into the function createCarDictionary
I was able to create a dictionary that creates the car brand as the key and the values as the remaining information in the txt file stored as tuples:
dict1 = {}
def createCarDictionary(datafile):
for line in datafile.splitlines():
key, value, value2 = map(str.strip, line.split('|'))
dict1[key] = value, value2
return dict1
datafile = open('data.txt', 'r').read()
createCarDictionary(datafile)
print(dict1)
OUTPUT
{'CAR': ('PRICE', 'RPM'), 'TOYOTA': ('21,000', '3,600'), 'HONDA': ('19,000', '4,000')}
So my question(s) is/are: What must I add to the function to 1) remove the commas in the numbers and 2) convert the tuple values into a list, so I can manipulate them later.