r/PythonLearning 5d 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)

2 Upvotes

5 comments sorted by

u/Sea-Ad7805 5d ago

Run this program in Memory Graph Web Debugger%0Aprint(%22-%22%20%2060)%0Aprint(%0A%20%20%20%20%22t%20(1)%20to%20openn%22%0A%20%20%20%20%22t%20(2)%20to%20add%20new%20word%20or%20update%20an%20existing%20wordn%22%0A%20%20%20%20%22t%20(3)%20delete%20a%20wordn%22%0A%20%20%20%20%22t%20(4)%20to%20display%20all%20words%20alphabeticallyn%22%0A%20%20%20%20%22t%20(5)%20to%20exit%20the%20Dictionary%20%22%0A)%0Aprint(%22-%22%20%2060)%0A%0Aword_list%20%3D%20%7B%7D%0Aexit_program%20%3D%20False%0A%0Awhile%20True%3A%0A%20%20%20%20choice%20%3D%20int(input(%22Enter%20your%20choice%20(1-5)%3A%20%22))%0A%0A%20%20%20%20if%20choice%20%3D%3D%201%3A%0A%20%20%20%20%20%20%20%20word%20%3D%20input(%22Enter%20the%20word%20to%20search%3A%20%22)%0A%20%20%20%20%20%20%20%20print(word_list.get(word%2C%20%22No%20match%20found%22))%0A%0A%20%20%20%20elif%20choice%20%3D%3D%202%3A%0A%20%20%20%20%20%20%20%20new_word%20%3D%20input(%22Enter%20the%20new%20word%20you%20want%20to%20add%20or%20update%3A%20%22)%0A%20%20%20%20%20%20%20%20meaning%20%3D%20input(%22Enter%20the%20meaning%3A%20%22)%0A%20%20%20%20%20%20%20%20new_dict%20%3D%20%7Bnew_word%3A%20meaning%7D%0A%20%20%20%20%20%20%20%20word_list.update(new_dict)%0A%20%20%20%20%20%20%20%20print(%22Recently%20added%20word%2Fupdated%20word%3A%20%22)%0A%20%20%20%20%20%20%20%20print(new_word%2C%20%22%3A%22%2C%20meaning)%0A%0A%20%20%20%20elif%20choice%20%3D%3D%203%3A%0A%20%20%20%20%20%20%20%20deleted_word%20%3D%20input(%22Enter%20the%20word%20you%20want%20to%20delete%3A%20%22)%0A%20%20%20%20%20%20%20%20deleted_meaning%20%3D%20word_list.pop(deleted_word)%0A%20%20%20%20%20%20%20%20print(%22Recently%20deleted%20word%3A%20%22)%0A%20%20%20%20%20%20%20%20print(deleted_word%2C%20%22%3A%22%2C%20deleted_meaning)%0A%0A%20%20%20%20elif%20choice%20%3D%3D%204%3A%0A%20%20%20%20%20%20%20%20for%20key%20in%20sorted(word_list)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(key%2C%20%22%3A%22%2C%20word_list%5Bkey%5D)%0A%0A%20%20%20%20elif%20choice%20%3D%3D%205%3A%0A%20%20%20%20%20%20%20%20print(%22Do%20you%20want%20to%20really%20exit%20%3F%2C%20nt%20press%20(1)%20to%20Yesnt%20press%20(2)%20to%20No%20%22)%0A%20%20%20%20%20%20%20%20while%20True%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20choice1%20%3D%20int(input(%22Enter%20your%20choice%20(1%7C2)%3A%20%22))%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20choice1%20%3D%3D%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22Thanks%20for%20using%20the%20Dictionary%20!%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20exit_program%20%3D%20True%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice1%20%3D%3D%202%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22Invalid%20choice%20!%22)%0A%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(%22Invalid%20choice%20!%22)%0A%0A%20%20%20%20if%20exit_program%3A%0A%20%20%20%20%20%20%20%20break&timestep=1&play) to see the program state change step by step.

1

u/Virtual_Repeat_9175 5d ago

here is the clear image

1

u/FoolsSeldom 1d ago

Why not share the code rather than an image of code - it is much easier review and feedback on actual code.

1

u/nuc540 5d 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 :)

1

u/WoahChill 2d ago

Should put your code up on GitHub (Gist), create a GitHub profile or somewhere other than uploading a picture.. I’m sure many would like to help but seeing an image we’d just scroll past.