那是不正确的语法。您有[]
一个list
,但您要将每个值分配给另一个值,该值更像是dict
,因此不起作用。您可以通过将其发送给dict()
函数以创建字典,以最小的更改来解决此问题:
>>> alphabet = dict(a = 0, b = 1, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8, ... i = 9, j = 10, k = 11, l = 12, m = 13, n = 14, o = 15, p = 16, ... q = 17, r = 18, s = 19, t = 20, u = 21, v = 22, w = 23, y = 24, ... x = 25, z = 26) >>> alphabet['b'] 1