我有一个表,其中包含:
table = [[1,'THEINCREDIBLES'],[2,'IRONMAN']]
我想将表中每个列表中的单词转换为其数字表示(ASCII)。
我试过了:
movie = 'THEINCREDIBLES'
h = 0
for c in movie:
h = h + ord(c)
print(h)
它有效,但如果我要使用上表中的列表列表,我会收到一条错误消息ord expected string of length 1
table = [[1,'THEINCREDIBLES'],[2,'IRONMAN']]
h = 0
for c in table:
h = h + ord(c)
print(h)
编辑@Sphinx
我已经搞定了:
table = [[1,'THEINCREDIBLES'],[2,'IRONMAN']]
h = 0
ordlist = []
for row in table:
for c in row[1]:
h = h + ord(c)
ordlist.append(row[0])
oralist.append(h)
h = 0
print(ordlist)
我的输出现在是:
[1,1029,2,532]
这几乎接近我想要的:
[[1,1029],[2,532]]
我如何将每个序数表示包含在上面的列表中的单个列表中?我是否为此目的引入一个新列表?