all & any
def all(*args, **kwargs):
"""
Return True if bool(x) is True for all values x in the iterable.
If the iterable is empty, return True.
"""
例:
print(all([1, 2, 3, 0])) # False
print(all([1, 2, 3])) # True
print(all([1, 2, 3, ''])) # False
print(all('')) # True
any
def any(*args, **kwargs):
"""
Return True if bool(x) is True for any x in the iterable.
If the iterable is empty, return False.
"""
例:
print(any([0, ''])) # False
print(any([1, 2, 3])) # True
print(any([1, 2, 3, ''])) # True
print(any('')) # False
随机推荐
- HDU 3068 (Manacher) 最长回文
求一个字符串的最长子串,Manacher算法是一种O(n)的算法,很给力! s2[0] = '$',是避免在循环中对数组越界的检查. 老大的代码: http://www.cnblogs.com/Big ...
- 51nod1486 大大走格子
容斥定理+dp...妈呀#1rp耗尽了难怪最近那么衰... #include<cstdio> #include<cstring> #include<cctype> ...
- css各浏览器的兼容性写法
各浏览器下的兼容性写法 老版Chrome -webkit-xxx FF -moz-xxx IE9 -ms-xxx opera ...
- 抛出自定义异常,spring AOP事务不回滚的解决方案
spring AOP 默认对RuntimeException()异常或是其子类进行事务回滚,也就是说 事务回滚:throw new RuntimeException("xxxxxxxxxxx ...
- 《C#高级编程》之泛型--1创建泛型类
.NET自从2.0版本开始就支持泛型. 非泛型链表 闲话休提,马上来看下非泛型的简化链表类,它可以包含任意类型的对象. LinkedListNode.cs中: 在链表中,一个元素引用另一个元素,所以必 ...
- [Mac][MySQL]如何启动MySQL Server
方法来自 MySQL 5.7官方手册 http://dev.mysql.com/doc/refman/5.7/en/osx-installation-launchd.html 有两种方法,另一种是命令 ...
- exception is org.hibernate.exception.DataException: Could not execute JDBC batch update at
没有什么问题,但是却报了Could not execute JDBC batch update的错,主要是配置文件设置了关联,数据却没有关联造成的,只要数据正确就没有问题. 另外,造成这个原因的还可能 ...
- 【自动化测试】Selenium 下载文件
用curl确定要下载的文件是什么类型的:另一种方法是使用requests 模块来查找内容类型 文件类型 http://tool.oschina.net/commons 1.先设置下载的目录,下载文件的 ...
- php 格式化数字 位数不足前面加0补足
本文引用自 http://www.fengfly.com/plus/view-62827-1.html 补0: <?php $var = sprintf("%03d", 12 ...
- 【UVa-442】矩阵链乘——简单栈练习
题目描述: 输入n个矩阵的维度和一些矩阵链乘表达式,输出乘法的次数.如果乘法无法进行,输出error. Sample Input 9 A 50 10 B 10 20 C 20 5 D 30 35 E ...