一,返回值为bool类型的函数 1.any()函数 any(iterable)->bool 当迭代器中有一个是Ture,则返回Ture;若interable=NUll,则返回False. >>> any([1,0]) True >>> any([0,0]) False >>> any([]) False >>> any([1,0,0]) True 注:在Python中, False相当于:0,[], (), {}, 0.0 , " ", ' ' . 应用:在一颗二叉树中,找出每一层中的最大元素(leetcode515)。 Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3,9] #类节点的定义class node(self) : def __init__(self,data) self.val=data self.right=NULL self.left=NULLclass Solution(object): def largestValues(self, root): maxlist=[] row=[root] while any(row): maxlist.append(max[node.val for node in row]) row=[kid for node in row for kid in node.left,node.right)