きつねたぬきだし

ちょっとしたメモ代わりに。

PyPI の Top 50 プロジェクトで予約語・組み込み関数の合計出現回数を調べてみた。

書いたスクリプトがこちら

gist: https://gist.github.com/kitsuyui/11cb65ef4f4630432bfa

引数にファイルを指定すると、そのファイル内の Python 予約語・組み込み関数名の出現回数を数え上げ、降順で TSV 形式で出力します。

例えば、このファイル自体の予約語・組み込み関数名の出現回数を出力するとこうなります。

$ python keyword_counting.py keyword_counting.py
in 11
for 10
import  8
if  7
yield   6
def 6
open    4
elif    3
return  3
from    1
help    1
format  1
sum 1
tuple   1
__name__    1
print   1
dir 1

対象は Python ファイルだけでなく、 Python ファイルを含むディレクトリや、 tar.gz, zip 形式などにも対応しています。

PyPI Ranking という PyPI での人気プロジェクトをまとめているサイトがあります。

PyPI Ranking

これを元に、 Top 50 プロジェクトでキーワードの出現回数を記録してみました。

自分のプロジェクトと出現頻度を比較してみると面白いかもしれません。

def    69445
if  48572
return  39990
None    34503
import  27266
in  24468
from    19493
not 17805
for 15311
class   14378
True    14318
else    12466
is  11888
False   10909
assert  8753
raise   7870
try 7530
and 6988
except  6662
len 5970
id  5857
elif    5402
isinstance  5143
pass    5131
or  4991
object  4128
list    3408
type    3104
str 2832
set 2655
as  2613
print   2529
__name__    2466
dict    2407
ValueError  2258
with    2048
lambda  2044
getattr 2022
property    2009
int 1897
super   1875
hasattr 1763
yield   1697
TypeError   1538
del 1432
filter  1386
finally 1330
range   1328
classmethod 1326
continue    1293
open    1232
while   1227
compile 1221
all 1129
Exception   1106
ImportError 1096
break   1085
KeyError    1071
tuple   989
next    954
file    940
AttributeError  882
format  840
repr    825
setattr 781
help    712
map 708
NotImplementedError 606
iter    550
bytes   517
bool    495
__doc__ 492
sorted  471
enumerate   448
basestring  427
buffer  423
dir 411
vars    404
unicode 400
float   377
max 357
global  347
zip 337
IOError 313
OSError 313
exit    295
min 293
callable    290
input   270
long    269
hash    259
AssertionError  258
xrange  249
RuntimeError    214
globals 206
IndexError  205
locals  201
frozenset   199
StopIteration   197
ord 178
issubclass  177
staticmethod    174
DeprecationWarning  168
any 164
__import__  162
SystemExit  157
NameError   151
chr 123
sum 119
eval    116
reversed    114
unichr  114
NotImplemented  107
SyntaxError 101
KeyboardInterrupt   101
reduce  99
hex 93
abs 91
apply   90
cmp 86
exec    82
slice   81
coerce  78
LookupError 67
reload  60
delattr 60
UnicodeDecodeError  58
divmod  58
pow 56
intern  55
memoryview  54
UnicodeError    53
PendingDeprecationWarning   50
Warning 47
OverflowError   46
bin 45
raw_input   44
EOFError    39
license 38
execfile    36
bytearray   35
UnicodeEncodeError  34
ZeroDivisionError   33
UserWarning 30
StandardError   29
quit    29
round   28
copyright   26
RuntimeWarning  25
EnvironmentError    25
MemoryError 24
SyntaxWarning   21
BaseException   21
complex 14
__debug__   10
__package__ 6
UnboundLocalError   6
oct 5
SystemError 4
Ellipsis    3
IndentationError    3
credits 3
GeneratorExit   3
ReferenceError  3
FloatingPointError  1
UnicodeTranslateError   1
ArithmeticError 1
TabError    1