Python,如何从列表中的列表中打印特定项目? [英] Python, how to print specific items from lists in lists?
本文介绍了Python,如何从列表中的列表中打印特定项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在列表 num_list
中打印所有列表的第一项和最后一项.
I am trying to print the first and last item of all the lists inside my list of lists num_list
.
num_list = [[1,2,3],[10,20,30],[100,200,300]]
for x in range(0,3):
for y in range(0,1) and range(2,3):
print(num_list[x][y])
但这只是打印 3,30,300
而跳过 1,10
和 100
.
But this is just printing 3,30,300
and skipping the 1,10
and 100
.
什么是解决此问题的好方法?
What is a good way to solve this problem?
推荐答案
可能是最小的解决方案:
Probably the smallest solution:
num_list = [[1,2,3],[10,20,30],[100,200,300]]
for x in num_list:
print(x[0], x[-1])
这篇关于Python,如何从列表中的列表中打印特定项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文