The itertools module has all kinds of fun stuff. What does this have to do with the itertools module? 例如,编写random.seed()或itertools . For instance, writing random. seed() or itertools . 在这个例子里,给出一个已经按长度排序的名字列表,itertools . In this example, given a list of names already sorted by length, itertools .
我已经提到了more_itertools 本文中讨论的其他内容。 I have mentioned more_itertools among others discussed in this post. 据我所知,没有一行或两行的itertools 配方功能可选垫。 As far as I know, there's no one- or two-line itertools recipe for a function that optionally pads. 我一直在寻找有用的东西itertools 但我找不到任何明显有用的东西。 I was looking for something useful in itertools but I couldn't find anything obviously useful. 如果你想要再循环一次(例如,在接下去的for循环里面),你得调用itertools . If you want to loop through it again(say, in the upcoming for loop), you need to call itertools . 我一直在寻找有用的东西,itertools 但我找不到任何明显有用的东西。 I was looking for something useful in itertools but I couldn't find anything obviously useful. 赞成这一点,因为它适用于生成器(没有len)并使用通常更快的itertools 模块。 Upvoted this because it works on generators(no len) and uses the generally faster itertools module. 二元谓词可以直接用作filter()或itertools .ifilter()的谓词。 Binary predicates can be used directly as predicates for filter() or itertools . ifilter(). Islice()使得清楚的是,这些功能分别由random和itertools 模块实现。 Izip() makes it clear that those functions are implemented by the random and itertools modules respectively . 同样,这是一个相当不错的假想的例子,如果你真的想数到500亿,你可能会使用itertools 。 Again, this is a pretty contrived example, you probably would use itertools if you really wanted to count to 50 billion.:. Islice()这种写法明确了这些函数是由random与itertools 模块分别实现的。 Izip() makes it clear that those functions are implemented by the random and itertools modules, respectively. 使用全新的Python2.6,您可以使用itertools 模块的标准解决方案来返回迭代的笛卡尔积:. With the brand new Python 2.6, you have a standard solution with the itertools module that returns the Cartesian product of iterables:. 有两个标准库(functools,itertools )提供了Haskell和StandardML中久经考验的函数式程序设计工具。 There are two standard libraries(Functools, itertools ) that provide proven functional programming tools in Haskell and standards ml. 我还没有找到关于如何实际使用Python的itertools .groupby()函数的可理解的解释。 I haven't been able to find an understandable explanation of how to actually use Python's itertools . groupby() function. Itertools 模块里有各种各样的有趣的东西,包括permutations()函数,它把查找排列的所有辛苦的工作的做了。The itertools module has all kinds of fun stuff in it, including a permutations() function that does all the hard work of finding permutations. 或者,如果给出cum_weights序列,则根据累积权重(可能使用itertools .accumulate()计算)进行选择。 Alternatively, if a cum_weights sequence is given, the selections are made according to the cumulative weights(perhaps computed using itertools . accumulate()). 第二个例子,来做一些有趣的数学题:使用生成器表达式、itertools .combinations以及itertools . For the second example, let's do something more mathematically interesting: using generator expressions and itertools . combinations and itertools .
Display more examples
Results: 21 ,
Time: 0.0146