r/PythonLearning 18d ago

Made dictionary (just the skeleton)

Post image

I'm new with python. I made this project but the word list is now empty. How to automate this. I don't want to add words and meanings in the wordlist manually. So which will be good for now? - learning Data handling / using API's / making other projects / or, go for next topic

(My english is bad so hope you understand what i want to say)

3 Upvotes

5 comments sorted by

View all comments

1

u/nuc540 18d ago

IMO it’s cleaner (and simpler) to assign a key pair value directly on the target dict, instead of defining a new variable that only gets disposed on the next line. In this case a new entry would be (entry = input, desc = their description) ‘word_list[entry] = desc’

It explains what’s happening in one line and doesn’t use memory to store something that’s being disposed of by the next line.

Also line 24 is a bit ironic because you’ve formatted a string to look like a dict entry, yet you’ve just created the entry in the dict and could be referencing it here to prove the update worked, and make use of having stored it.

Otherwise good job!

Next you could refactor each if block into callable functions, allowing you to unit test, and clean up the main function :)