I asked the question How to implement filter in python yesterday. Since I am a beginner, and English is not my first language, I had a hard time trying to clearly explain what I wanted to ask. So, I ended up using multiple photos to explain my situation.
Eventually, I received two answers. One answer is from Martijn Pieters which explains how to execute a query in the database SQLAlchemy.
But because of my poor knowledge of programming, at the first glance, I could not make out how his example works. I have to admit that I didn't fully look into the documentation of SQLAlchemy, but I was desperate to get my job done as quickly as possible, so I ended up querying out all the data in the database into a Python dictionary and used the method provided by TurpIF (second answer).
I assume that my method is not good for a big database as it has to query out the whole database into memory before I start doing anything. It would be much wiser to filter out at the database layer rather than in Python code itself.
But now, I am in a dilemma. Should I mark the answer that I ended up using as accepted or the one that seems to be a better way? What should I do if I see the same problem in future Stack Overflow posts?