문제

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