I currently has an Excel file with one column for ItemID and one column for ItemName in this style:
ItemID, ItemName
2, Apple
4, Orange
5, Pear
6, Banana
15, Kiwi
I am open to converting this data in to whatever format would be easiest, but I need an explanation of how to go about that conversion.
I want to pass a list like this:
[‘Apple’, ‘Pear’, ‘Banana’]
And have it output a list like this:
[2,5,6]
I have looked at doing this with sqlite3 but I can’t find how to pass a whole list as input and I can’t find an easy way to convert my Excel file into some sort of .sql or .db file that sqlite3 could dig through. I really don’t care what sort of file (or even file-type item) I end up having to convert my Excel file into, I just want the look up process to be efficient.
EDIT:
In the actual case I’m working with there are about 8800 items. Also, each is unique such that ItemID is unique and ItemName is unique. That said, some item names are similar with just an extra word added on the end such as ‘Orange Small’ and ‘Orange Large’.
This is basically the
csvmodule version of @inspectorG4dget’s answer. First, save your file incsvformat from Excel, producing something like this:Since you say that each ItemName is unique, we can use a dictionary to store the data. In python 2.7, and using a helper function like inspectorG4dget’s getIDs:
We can build a dictionary and access it: