1
回答
dictionary相关
【腾讯云】校园拼团福利,1核2G服务器10元/月!>>>   
dictionary = {"0":"0000", "1":"0001", "2":"0010",
          "3":"0011", "4":"0100", "5":"0101",
          "6":"0110", "7":"0111", "8":"1000",
          "9":"1001", "A":"1010", "B":"1011",
          "C":"1100", "D":"1101", "E":"1110",

          "F":"1111"}

table = input("Enter the dictionary's name: "), 此方法无法将dictionary 赋值给 table

我想问:如何以 input的方式将将dictionary 赋值给 table

(table = dictionary 此方法可行,但是我想以input的方式从几个dictionary中选择一个

举报
ye----ye
发帖于2年前 1回/62阅
共有1个答案 最后回答: 2年前

可以啊!   

bogon:~ changqingzhao$ python
Python 2.7.10 (default, Oct 23 2015, 18:05:06)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> dictionary = {"0":"0000", "1":"0001", "2":"0010",
...           "3":"0011", "4":"0100", "5":"0101",
...           "6":"0110", "7":"0111", "8":"1000",
...           "9":"1001", "A":"1010", "B":"1011",
...           "C":"1100", "D":"1101", "E":"1110",
...           "F":"1111"}
>>>
>>> table = input('=>:')
=>:dictionary
>>> table
{'A': '1010', 'C': '1100', 'B': '1011', 'E': '1110', 'D': '1101', 'F': '1111', '1': '0001', '0': '0000', '3': '0011', '2': '0010', '5': '0101', '4': '0100', '7': '0111', '6': '0110', '9': '1001', '8': '1000'}
>>>

顶部