equal
deleted
inserted
replaced
75 return tuple(self.func(obj)) |
75 return tuple(self.func(obj)) |
76 |
76 |
77 lazy_load = LazyProperty |
77 lazy_load = LazyProperty |
78 lazy_load_iter = LazyIteratorProperty |
78 lazy_load_iter = LazyIteratorProperty |
79 |
79 |
|
80 def first (iterable) : |
|
81 """ |
|
82 Returns the first item from the iterable that evaluates to True, otherwise None. |
|
83 |
|
84 >>> first((0, 1)) |
|
85 1 |
|
86 >>> first("abc") |
|
87 'a' |
|
88 >>> first(('', list(), (), False)) |
|
89 None |
|
90 """ |
|
91 |
|
92 for item in iterable : |
|
93 if item : |
|
94 return item |
|
95 |
|
96 else : |
|
97 return None |
|
98 |
|
99 |
80 # testing |
100 # testing |
81 if __name__ == '__main__' : |
101 if __name__ == '__main__' : |
82 import doctest |
102 import doctest |
83 |
103 |
84 doctest.testmod() |
104 doctest.testmod() |