Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary in a list
#1
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):

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.
Reply


Messages In This Thread
Dictionary in a list - by bashage - Dec-27-2023, 01:30 PM
RE: Dictionary in a list - by DPaul - Dec-27-2023, 03:25 PM
RE: Dictionary in a list - by deanhystad - Dec-27-2023, 04:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 645 Apr-29-2024, 04:38 PM
Last Post: Calab
  filtering a list of dictionary as per given criteria jss 5 754 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  How to add list to dictionary? Kull_Khan 3 1,052 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  check if element is in a list in a dictionary value ambrozote 4 2,042 May-11-2022, 06:05 PM
Last Post: deanhystad
  Dictionary from a list failed, help needed leoahum 7 2,050 Apr-28-2022, 06:59 AM
Last Post: buran
  how to assign items from a list to a dictionary CompleteNewb 3 1,623 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  Python, how to manage multiple data in list or dictionary with calculations and FIFO Mikeardy 8 2,695 Dec-31-2021, 07:47 AM
Last Post: Mikeardy
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,952 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  Python dictionary with values as list to CSV Sritej26 4 3,076 Mar-27-2021, 05:53 PM
Last Post: Sritej26
  convert List with dictionaries to a single dictionary iamaghost 3 2,892 Jan-22-2021, 03:56 PM
Last Post: iamaghost

Forum Jump:

User Panel Messages

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