Python Forum
Help adding items to a glossary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help adding items to a glossary
#2
So far, your script looks good.

There are a couple things I would change. In show_flashcard(), there are two issues. First, it does not take an argument which means that glossary is a global variable. Using global variables like that is a bad practice. Anything referenced inside a function should be local - either passed in as an argument or defined within the function. Changing the function signature to show_flashcard(glossary) will improve it.

The second issue with it is only line 18. While it technically works, I would use dict.keys() instead of list(dict). Probably just a style difference.

For your inputs, I recommend calling str.lower(), str.upper(), or something equivalent. That way, your comparisons permit for uppercase and lowercase inputs from the user.

As for your actual question... I suppose adding to the dictionary is the obstacle. You can call the dict.update() method to insert new keys and values. For your project, I recommend that your function checks for the new key before requesting the definition. That way, you can ensure that the user is not overwriting definitions that have already been entered. Does that help?
Reply


Messages In This Thread
Help adding items to a glossary - by lga13 - Jan-07-2019, 11:59 PM
RE: Help adding items to a glossary - by stullis - Jan-08-2019, 03:31 AM
RE: Help adding items to a glossary - by perfringo - Jan-08-2019, 06:39 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020