Question

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?

Était-ce utile?

La solution

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.

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top