小编AR.*_*ard的帖子

如何仅将字符串列表的一部分转换为整数

我有一个列表列表,例如:

[['c', '2', '3', '4', 'd', '1'], ['e', '14', '16', '18', 'f', '1'], etc.]
Run Code Online (Sandbox Code Playgroud)

它们都遵循相同的模式(一个字符串,三个数字字符串,一个字符串,一个数字字符串)。我想将所有数字字符串都转换为整数,但这样做有困难。

I have tried an exception loop, which doesn't seem to be working (I'm not sure why). I know its targeting the sublists as originally I got a value error of int() doesn't recognise base 10 'c' (the first letter in the first element of the sublist.

[['c', '2', '3', '4', 'd', '1'], ['e', '14', '16', '18', 'f', '1'], etc.]
Run Code Online (Sandbox Code Playgroud)

When I print the results with …

python int list python-3.x

5
推荐指数
1
解决办法
71
查看次数

标签 统计

int ×1

list ×1

python ×1

python-3.x ×1