Dec-27-2023, 01:30 PM
(This post was last modified: Dec-27-2023, 03:19 PM by Gribouillis.)
Hi,
I'm learning French and Python, and I thought I'd combine the two. My goal is to make a glossary written in Python, where each word is a dictionary with three keys (word category, article and chapter in which it first appears) and values. I'd like to store those words in a list; this list is for nouns. So far I've come up with this (indentation is screwed up, but originally correct):
quai:
* noun
* le
* chapter 1a
I've written this:
I'm learning French and Python, and I thought I'd combine the two. My goal is to make a glossary written in Python, where each word is a dictionary with three keys (word category, article and chapter in which it first appears) and values. I'd like to store those words in a list; this list is for nouns. So far I've come up with this (indentation is screwed up, but originally correct):
voyager_glossary_noun = [] voyage = { 'category': 'noun', 'article': 'le', 'chapter': '1a', } voyager_glossary_noun.append(voyage) quai = { 'category': 'noun', 'article': 'le', 'chapter': '1a', } voyager_glossary_noun.append(quai)I have trouble accessing the various data. I'd like to have an output like this:
quai:
* noun
* le
* chapter 1a
I've written this:
1. for word in voyager_glossary_noun: 2. 3. for key, value in voyage.items(): 4. msg = f"\t* {value}" 5. print(msg)I don't understand how to display the word itself, and I get the impression that I should be able to do that with one line of code on the second line. Any tips? I'm an almost total beginner, and simple code and explanation would be greatly appreciated.
Gribouillis write Dec-27-2023, 03:19 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.