【发布时间】:2022-01-18 23:11:51
【问题描述】:
我需要将列表字母表中的数字从列表 m_b 中数字字母表中的索引 key_m 开始替换为列表 c1 中的索引
from operator import setitem
def replace():
alphabet = [['a'], ['b'], ['c'], ['d'], ['e'], ['f'],
['g'], ['h'], ['i'], ['j'], ['k'], ['l'],
['m'], ['n'], ['o'], ['p'], ['q'], ['r'],
['s'], ['t'], ['u'], ['w'], ['v'], ['x'],
['y'], ['z']]
key_m = 10
c1 = [17, 10, 21, 22, 1]
m_b = [['y'], ['a'], ['#'], ['b'], ['o'], ['i'],
['c'], ['d'], ['e'], ['f'], ['g'], ['h'],
['j'], ['k'], ['l'], ['m'], ['n'], ['p'],
['q'], ['r'], ['s'], ['t'], ['u'], ['v'],
['w'], ['x'], ['z'], ['_'], ['-'], ['!'],
['?'], ['$'], ['/'], ["@"], ['+'], ['%']]
for b, c in zip(c1, m_b):
setitem(alphabet, b, c)
print(alphabet)
预期结果是字母 = [['a'], ['b'], ['c'], ['d'], ['e'], ['f'], [' g'], ['h'], ['i'], ['j'], ['p'], ['g'], ['t'], ['u'], ['a' ], ['p'], ['q'], ['r'], ['s'], ['t'], ['u'], ['w'], ['v'], ['x'],['y'], ['z']]
但实际结果是alphabet = [['a'], ['o'], ['c'], ['d'], ['e'], ['f'], ['g'], ['h'], ['i'], ['j'], ['a'], ['l'], ['m'], ['n'], [' o'], ['p'], ['q'], ['y'], ['s'], ['t'], ['u'], ['#'], ['b' ], ['x'], ['y'], ['z']]
【问题讨论】:
-
预期结果是什么?
-
... 而实际结果呢?您遇到的具体问题是什么?欢迎来到 SO。请务必阅读How to Ask
-
预期结果是字母 = [['a'], ['b'], ['c'], ['d'], ['e'], ['f'], ['g']、['h']、['i']、['j']、['p']、['g']、['t']、['u']、[' a'], ['p'], ['q'], ['r'], ['s'], ['t'], ['u'], ['w'], ['v' ], ['x'],['y'], ['z']]
-
edit你的帖子添加预期的输出?
-
为什么是列表而不是长字符串?