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?

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top