如何将字符串数字转换为列表中的整数? [英] How to convert strings numbers to integers in a list?
本文介绍了如何将字符串数字转换为列表中的整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个清单说:
['batting average', '306', 'ERA', '1710']
如何在不接触字符串的情况下转换预期的数字?
How can I convert the intended numbers without touching the strings?
感谢您的帮助.
推荐答案
changed_list = [int(f) if f.isdigit() else f for f in original_list]
这篇关于如何将字符串数字转换为列表中的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文