Exercise 48, my version of lexicon.py (Need advice)

Hello together, hope you are all well.

This is my first post here.

I am writing because I think I am struggling with understanding of class and function usage.

I am able to solve the exercises, writing my own code, but I think I am something missing.

Please access my version of lexicon.py using the link from below:
lexicon.py

I used pytest to pass all 6 test. All succeed.

I just need your opinion to understand if I am doing right.

I created my own game, with a little different gameplay.

After I will be able to improve my game code as much as possible I will surely come back for some more help.

Thank you.

#stayhomebesafe

Almost. You should use a dict:

x = {“north”: “direction”}

What would that do compared to what you have?

Hello Zed,

I am little confused.

It will remove the code which repeats, thus making the function less, easier to understand and more functional?

Yes, it will also work more correctly. I’d say rewrite this code using a dict so you have a better understanding of what’s going on, and also so you can prove to yourself it wasn’t luck. The idea is, with a dict I can do:

word_list.get(‘north’)

And that will give me ‘direction’. Then word_list can be:

word_list = {‘north’: ‘direction’}

Make sense?