Pregunta

Good day! I've been trying to set a dictionary in Python 3.4 that can be used to map basic symbols and letters using "utf-8" . (for example coma map to "equal to" sign, or Apostrophe into curly bracket sign etc.

dictionary = {a='alpha', b='b', ,='=', '='}' }

It's important to notice that I want to be able to use their indexes afterward

dictionay[,] = '}' e.g 

Any suggestion?

¿Fue útil?

Solución

You can't initialize dictionaries that way, its simply the wrong syntax. Since you want to use unicode characters as keys, your keys need to be strings.

This thing here should do what you want:

dictionary = {'a':'alpha', 'b':'b', ',':'=', "'":'}' }

Notice how all the keys are strings. If you set up the dictionary in this way you need to use the colon instead of the equal sign to assign values to keys.

Otros consejos

Your problem seems to be the equal sign...

Python dict is like this d = {",": "}" }

but not an equal sign.

Converting a comma will be d[","]

Any hashable objects can be a key in python

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top