小编dne*_*nez的帖子

如何转换为Python列表理解

ls = ['abc', 56, 49, 63, 66, 80]
for i in ls:
    if(isinstance(i, int) or isinstance(i, float)):
        for i in range(len(ls)):
            ls[i] = str(ls[i])
Run Code Online (Sandbox Code Playgroud)

我可以知道如何创建上面代码的列表理解吗?

我正在尝试以下但不工作

if (s for s in ls isinstance(s, int) or isinstance(s, float)):
    for i in range(len(ls)):
        ls[i] = str(ls[i])
Run Code Online (Sandbox Code Playgroud)

python list for-comprehension python-3.x

2
推荐指数
1
解决办法
1533
查看次数

标签 统计

for-comprehension ×1

list ×1

python ×1

python-3.x ×1