I'm trying to let the dictionary called
theInventory = {}
to sort the following items, so i can add price or view the books by authors and etc.
It's my homework problem. so i need to use dictionary and multi-value using 2D list
Let the some text file called database.txt contains
last name/first name/quantity/price
Shakespeare,William,Romeo And Juliet,5,5.99
Shakespeare,William,Macbeth,3,7.99
Dickens,Charles,Hard Times,7,27.00
Austin,Jane,Sense And Sensibility,2,4.95
Is it possible to do the following?
inFile = (database.txt, "r")
For line in inFile:
aLine = []
aLine = line.split(",") # dont know how to split by ,
theInventory[aLine[0] + ", " + aLine[1]] = list[list[aLine[3], int(aLine[4]), float(aLine[5])]]
inFile.close()
the result will be like
>print (theInventory)
>> {"Shakespeare, William": [["Romeo And Juliet", 5, 5.99], ["Macbeth", 3, 7.99]], "Dickens, Charles": [["Hard Times", 7, 27.00]], "Austin, Jane": [["Sense And Sensibility", 2, 4.95]]}
so that you can modify quantity and price of the certain book.
or even add books to dictionary.