ls = [["Bob", 13 ,156], ["Jonny", 24, 180]]
## this line loops through the ls and unpack the 3 values to variable names
## name, age and value. condition "if age>=18" filters user matching the condition
_18_or_above = [name for name, age, value in ls if age>=18]
print(_18_or_above)
## this lines sort the list by first element of list item which is age
sorted_by_age = sorted(ls, key=lambda x: x[1])
print(sorted_user)
如果列表中的列表长度相同,那么下面的解决方案就是工作
列表理解单行代码
你可以这样做
您只需执行索引的索引。你知道吗
例如在嵌套列表中
循环通过也是一样的 例如
相关问题 更多 >
编程相关推荐