python - 仅更新嵌套循环中的整数
问题描述
swim=[['Cycle Shoes+Goggles', 1.25],
['Cycle shoes+Sunglasses', 1],
['Run shoes+Goggles', 1.33]]
swim_s = 50
def update1(lst1):
for i in lst1:
i[1]*=swim_s
update1(swim)
目前,该程序只会将第一个整数乘以 50,但我将如何对列表中的每个整数执行此操作(完整列表将有超过 10 个整数)
解决方案
Check if it's an instance of int
using isinstance
:
def update(lst):
for ele in lst1:
for i in range(len(ele)):
if isinstance(ele[i], int):
ele[i] *= 50
推荐阅读
- android - 如何确保在多次按下按钮后仅打开一次活动
- php - 注册后,当我转到主页时出现错误 - “尝试获取非对象的属性 'blog_name'”
- python - 如何在类中获取和使用实例变量?
- python - 为什么这个 lambda 表达式不起作用?
- hadoop - 与 LDAP 集成时无法登录 NiFi
- ejs - 编译 ejs 代码时出现 EJS 语法错误
- python - Kivy IDs needing a clock schedule
- nlp - 无法在“大型”模型上使用现有代码与基础转换器一起使用
- c# - 针对云驱动器的文件 readallbytes 有时会引发云操作无效
- c++ - 自 Qt 6.0.0 以来,QPdfWriter 未正确嵌入标准字体