我尝试过:
my_list = ["1, 2, 3", "4, 5, 6"]
new_list = []
for e in my_list:
for sub_e in e:
new_list.append(int(sub_e))
但是我认为它正在1,
,2,
等上迭代。如何将["1, 2, 3"]
转换为整数[1, 2, 3]
的列表?
我想要的输出是整数列表:[1、2、3]
答案 0 :(得分:2)
尝试:
my_list = ["1, 2, 3", "4, 5, 6"]
new_list = []
for e in my_list:
for sub_e in e.split(","):
new_list.append(int(sub_e))