SignalProcessed
SignalProcessed

Reputation: 371

Python: What storage method to use for multi-property dictionary?

I'm relatively new to coding in python. I know most of the syntax, but actually applying it within real programs is new to me. I wanted to know, if I have some item with multiple properties, how would I store that?

I am creating a Japanese learning tool, following a textbook, and I need a way to store, and later access the vocabulary. For example...

If I have the word おはよう, this in romanized type is "ohayou", and its definition is "Good Morning", also this vocab is located in "Lesson 1" of the book.

I was thinking of creating a dictionary, with maybe a tuple/array/list for the value, or key to store more properties per vocab word. Then I thought maybe I could use a class as well, but thought I would need a class for each vocab word as objects? I just want to know what would be the most efficient, and easy storage method for these vocab words and all their different English, and Japanese properties.

Upvotes: 1

Views: 79

Answers (1)

Solaxun
Solaxun

Reputation: 2792

This is pretty broad, but your guiding consideration should be that you need to provide hashable keys. Given your constraints, I think a tuple (or namedtuple) would fit well. Namedtuple operates like a record, or lightweight class, so you can get the benefits of calling with dot notation while having an immutable data structure.

Upvotes: 2

Related Questions