python一个列表,多个字符串,不是纯数字的,如何转换为的数字列表

a=["a","12","23","b","c","2"]
转化为:
b=["a",12, 23 ,"b","c", 2]


def int_it(v):
    try:
        return int(v)
    except:
        return v
a=["a","12","23","b","c","2"]
b = [int_it(each) for each in a]
print b

温馨提示:答案为网友推荐,仅供参考
相似回答