Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> data = 'spam123'
>>> bool(filter(lambda s:s.isupper(),data))
False
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> data = 'spam123'
>>> bool(filter(lambda s:s.isupper(),data))
True
If anyone is familiar with it, please explain it.
http://qiita.com/trsqxyz/items/50e6e59e23995b6c2b41#comment-d01210d7bd8f60d2c590 It seems that the reason why filter () returned the list in the 2nd system is that the 3rd system now returns the iterator.
@shiena Thank you! !!
The Boolean value has changed because the empty list has changed to an iterator object. Dive into Python 3 seems to be useful here. So
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> data = 'spam123'
>>> bool(list(filter(lambda s:s.isupper(),data)))
False
have become It's important to verify the functions one by one
http://qiita.com/trsqxyz/items/50e6e59e23995b6c2b41#comment-945bff027756ad382a35 If you want to write something like a code example, any is better than bool.
ʻAny () is a built-in function that returns
Trueif any of the iterable elements are true. For all elements, there is ʻall ()
.
Certainly it seems more appropriate to use ʻany () `. Thank you very much.
and
bool () `>>> a=[0]
>>> bool(a)
True
>>> any(a)
False
ʻAny ()checks for each element Does
bool ()` feel like there is an element?
Recommended Posts