Python 嵌套列表理解中的 NameError
NameError in nested list comprehension with Python
objective是将下面的for循环转化为嵌套推导列表
txt=['-100:200','-15:0','0:15','30:45']
all_t=[]
for t in txt:
all_t.append([int ( idx ) for idx in t.split(":")])
进入
all_t=[int(idx) for idx in t.split(":") for t in txt]
但是编译return报错
NameError: name 't' is not defined
感谢有关此错误的任何帮助
txt=['-100:200','-15:0','0:15','30:45']
all_t=[[int(idx) for idx in t.split(":")] for t in txt]
print(all_t)
objective是将下面的for循环转化为嵌套推导列表
txt=['-100:200','-15:0','0:15','30:45']
all_t=[]
for t in txt:
all_t.append([int ( idx ) for idx in t.split(":")])
进入
all_t=[int(idx) for idx in t.split(":") for t in txt]
但是编译return报错
NameError: name 't' is not defined
感谢有关此错误的任何帮助
txt=['-100:200','-15:0','0:15','30:45']
all_t=[[int(idx) for idx in t.split(":")] for t in txt]
print(all_t)