擅长:python、mysql、java
<p>大多数Pythonic是编写一个小的辅助函数,并将其放入您信任的“实用程序”模块(或适当包的子模块,如果您有足够的;-):</p>
<pre><code>import itertools as it
def count(iterable):
"""Return number of items in iterable."""
return sum(1 for _ in iterable)
def count_conditional(iterable, predicate=None):
"""Return number of items in iterable that satisfy the predicate."""
return count(it.ifilter(predicate, iterable))
</code></pre>
<p>实际上,选择如何实现这些实用程序并不重要(您可以随时选择在Cython中重新编码其中的一些实用程序,例如,如果使用这些实用程序对应用程序进行的某些分析显示它是有用的):关键是将它们作为自己有用的实用程序库,有了名字和调用模式,你就可以像以前一样,让你最重要的应用程序级代码更清晰、可读性更强、更简洁,如果你把它塞满了内联的扭曲!-)</p>