itertools.count()作为内置函数 [英] itertools.count() as built-in

查看:174
本文介绍了itertools.count()作为内置函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有机会让itertools.count()成为

内置函数之一?这是一个很棒的小功能,我发现自己

在我写的每个模块中导入它。


-Janto

Is there any chance of itertools.count() ever becoming one of the
built-in functions? It''s a wonderful little function and I find myself
importing it in every module I write.

-Janto

推荐答案

2006年5月29日上午4:14, ja **** @ gmail.com 写道:
On 29/05/2006 4:14 AM, ja****@gmail.com wrote:
是否有任何机会让itertools.count()成为内置函数之一?这是一个很棒的小功能,我发现自己
在我写的每个模块中导入它。
Is there any chance of itertools.count() ever becoming one of the
built-in functions? It''s a wonderful little function and I find myself
importing it in every module I write.




每个模块?你使用任何/许多其他itertools函数?关注

给我们一个典型的itertools.count用法样本?


干杯,

John



Every module?? Do you use any/many other itertools functions? Care to
give us a sample of your typical usage of itertools.count?

Cheers,
John


我有一个大约6000行的项目,其中我使用count()20次。它

有14个模块,其中10个我需要明确导入。


许多用法的形式如下:

for item,n in zip(items,count(N)):

dostuff


其中大约一半是由于使用了pylab .subplot(x,yn),其中
需要n> = 1的值。所以我想要N = 1。枚举内置从0开始



我还写出以n = 1开头的文本报告。


我也是对于n,组件,zip中的旋转(count(),

排序(tools.component_files()。keys()),all_symbol_rotations) >
其中枚举版本看起来更令人困惑且容易

搞砸

for n,组件,旋转

枚举(sorted(tools.component_files()。keys()),all_symbol_rotations)


更多示例如下。请注意,我发现指定

最后计数更自然,因为它通常不如其他值重要。

这与枚举给出的顺序不同,所以我更多

倾向于使用count()。

mutated_symbols_and_names = zip(mutated_symbols,(("<%s mutation%)对于计数()中的m,s>"%

(分量,m))

edge_weight = dict(zip(Intersection.types,count(1)) (

for(component,filename),n in zip(components,count()):

for(component,filename),component_count in

zip(tools.component_files()。items(),count()):

I have a project of around 6000 lines where I used count() 20 times. It
has 14 modules, 10 of which I needed an explicit import.

Many of the usages are of the form:

for item, n in zip(items, count(N)):
dostuff

Around half of these are due to using pylab.subplot(x,y.n), which
requires values for n>=1. So I want N=1. The enumerate builtin starts
from 0.
I also write out textual reports that start with n=1.

I also have things like
for n, component, rotations in zip(count(),
sorted(tools.component_files().keys()), all_symbol_rotations)
where the enumerate version just looks even more confusing and easy to
mess up
for n, component, rotations in
enumerate(sorted(tools.component_files().keys()), all_symbol_rotations)

Some more examples follow. Note that I find it more natural to specify
the count last as it''s usually less important than the other values.
This is different from the order given by enumerate, so I''m more
inclined to use count().

mutated_symbols_and_names = zip(mutated_symbols, (("<%s mutation %s>" %
(component, m)) for m in count()))
edge_weight=dict(zip(Intersection.types, count(1)))
for (component, filename), n in zip(components, count()):
for (component, filename), component_count in
zip(tools.component_files().items(), count()):


哦,我使用重复,链和循环相当多。但我不介意

导入它们,因为它们通常仅限于一个模块。

Oh and I use repeat, chain and cycle quite a bit. But I don''t mind
importing them as they are usually limited to one module.


这篇关于itertools.count()作为内置函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆