python两层嵌套 [i for x in L for i in x]

大家都见过 [x for x in L ]
可能没见过 [i for x in L]
positive_pairs = [(1,2),(3,4),(5,6),(7,8),(70,80)]
negtive_pairs = [(10,20),(30,40),(50,60),(70,80)]

print([i for x in positive_pairs])

结果: [range(0, 4), range(0, 4), range(0, 4), range(0, 4), range(0, 4)]

print(type([i for x in positive_pairs][0]))

结果:

相当于啥也不是!!!

一定没见过 [i for x in L for i in x]
positive_pairs = [(1,2),(3,4),(5,6),(7,8),

python两层嵌套 [i for x in L for i in x]最先出现在Python成神之路

版权声明:
作者:Alex
链接:https://www.techfm.club/p/14052.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>