Correct Syntax to read Data from an Arrayvariable ?

Hi

I’ve something like this:

model.labels

Which returns me this:

{'de': ['Flugzeug'], 'fr': ['avion'], 'en': ['airplane']}

What I want is to get for example the name for airplane in german.

I tried:

model.labels['de']

But this returns me an error.

What is the correct Syntax to get the word for airplane in german ?

Kind regards
Alain

The type of data structure is called a dictionary in python.
The syntax you use is correct, why the string is in a list I don’t know.
To get more help you need to provide the error message and more of the context.


>>> airplanes
{'fr': ['avion'], 'de': ['Flugzeug'], 'en': ['airplane']}
>>> airplanes['de']
['Flugzeug']

It works now.
I don’t know what my little dumphead has done wrong before.

Thanks anyway.

Kind regards
Alain

any reason for using lists of strings instead of plain strings?

Sorry I don’t understand the question, what’s the difference ?

Kind regards
Alain

{'de': ['Flugzeug'], 'fr': ['avion'], 'en': ['airplane']}

vs.

{'de': 'Flugzeug', 'fr': 'avion', 'en': 'airplane'}

If the dictionary maps language code keys to single translations of a common word, there is really no need to put the translations in lists. It takes more memory and is less efficient if you use lists with a single string inside.