A Python Biology Dictionary

Last year I had to prepare for a biology test, so I decided to combine business with pleasure and write my own biology dictionary on Python: it provided a brief definition and the pages on the book I had to see to find what I needed.

Python Implementation

from fuzzywuzzy import process
import pandas as pd

file = pd.read_excel('dizionario.xlsx', index_col=0)
while True:
    request = input('Enter the words you wanna look up in the biodictionary separated by a comma')
    queries = request.split(',')

    for query in queries:
        print(query)
        matches = process.extract(query, file.index, limit=file.shape[0])
        for match in matches:
            if match[1] >= 90:
                print(match[0])
                print(file.loc[match[0], 'book_pages'])
                print(file.loc[match[0], 'definition'])
                print('\n\n')

The libraries I used are:

pandas, which lets me easily read the dictionary excel file, which I had written earlier;

fuzzywuzzy, a very nice library which calculates string similarity.

How does it work?

The program reads the excel file and turns it into a pandas DataFrame. After that you are requested to enter some words separated by a comma to search in the dictionary for all of them.

For each word in the queries list, the program, with fuzzywuzzy’s process.extract function, calculates the string similarity of each query to each of the words you can look up on the dictionary.

Finally, if the word is similar enough, it will print the desired information on the screen and start the process again, you have to interrupt it manually to make it stop.

Let’s see a sample output (the program is in italian but I’ll let you understand).

Enter the words you wanna look up in the biodictionary separated by a comma amminoacil T-rna sintetasi
 amminoacil T-rna sintetasi
amminoacil-trna-sintetasi
65.0
famiglia di enzimi attivanti che carica ciascun tRNA con l'amminoacido corrispondente



Enter the words you wanna look up in the biodictionary separated by a comma

So, the program prints what you were looking for, the voice on the dictionary, the page where I can find it and a brief definition.

Let’s see what happens if you’re in a hurry and you misspell a word:

Enter the words you wanna look up in the biodictionary separated by a comma ammncl T-rna sntets
 ammncl T-rna sntets
amminoacil-trna-sintetasi
65.0
famiglia di enzimi attivanti che carica ciascun tRNA con l'amminoacido corrispondente



Enter the words you wanna look up in the biodictionary separated by a comma

The program is able to find it anyway.

So that’s a possible implementation of a nice Python Dictionary, which you may find helpful in many situations.

Scroll to top