Python 列表中的字符串列表

Python 列表中的字符串列表,python,Python,我有多个字符串列表,在一个列表中。我想把数字字符串改成整数 例:- 我想要的是: [[123,'string','list']['words','python',456]['code',678,'links']] 我试过使用- W=range(len(L1)) Q=range(2) if (L1[W][Q]).isdigit(): (L1[W][Q])=(int(L1[W][Q])) 当我尝试上面的代码时,出现了一个错误。类似这样的错误: >>> myl

我有多个字符串列表,在一个列表中。我想把数字字符串改成整数

例:-

我想要的是:

[[123,'string','list']['words','python',456]['code',678,'links']]
我试过使用-

W=range(len(L1))       
Q=range(2)
if (L1[W][Q]).isdigit():
   (L1[W][Q])=(int(L1[W][Q]))
当我尝试上面的代码时,出现了一个错误。

类似这样的错误:

>>> mylist = [['123','string','list'], ['words','python','456'], ['code','678','links']]
>>> [ [(int(item) if item.isdigit() else item) for item in sublist] for sublist in mylist]
[[123, 'string', 'list'], ['words', 'python', 456], ['code', 678, 'links']]
使用:


请与我们分享您迄今为止所做的尝试。
>>> mylist = [['123','string','list'], ['words','python','456'], ['code','678','links']]
>>> [ [(int(item) if item.isdigit() else item) for item in sublist] for sublist in mylist]
[[123, 'string', 'list'], ['words', 'python', 456], ['code', 678, 'links']]
L1=[['123','string','list'],['words','python','456'],['code','678','links']]
for item in L1:
    for i in range(0,len(item)):
        if(item[i].isdigit()):
            item[i] = int(item[i])

print(L1)