我有这样的名单:
ciri = ['[7534, 16210, 16820, 6254, 11778, 28630, 22527, 10217,....]', '[7534, 16210, 16820, 6254, 11778, 28630, 22527, 10217,....]'...]你能帮我转换成这样的列表吗?
[[7534, 16210, 16820, 6254, 11778, 28630, 22527, 10217,....], [7534, 16210, 16820, 6254, 11778, 28630, 22527, 10217,....]...]这是我的密码
cur.execute(sql)
results = cur.fetchall()
ciri = []
for row in results:
Penciri = row[2]
Name = row[1]
ciri.append(Penciri)
out = map(int, ciri)
print out, "\n"但我有这样的错误信息

发布于 2015-05-10 15:15:26
你可以这样做,
In [16]: ciri = ['[7534, 16210, 16820, 6254, 11778, 28630, 22527, 10217]']
In [17]: new_list = [[ int(item.replace('[','').replace(']','')) for item in ciri[0].split(',') ]]
In [18]: new_list
Out[18]: [[7534, 16210, 16820, 6254, 11778, 28630, 22527, 10217]]https://stackoverflow.com/questions/30152572
复制相似问题