pyo3/examples/word-count/word_count/__init__.py
messense 43a5d6f1b4 Test and benchmark word-count example (#60)
* Test and benchmark word-count example

* Optimize rust word_count
2017-07-26 12:37:36 +08:00

18 lines
420 B
Python

# -*- coding: utf-8 -*-
from __future__ import absolute_import
from ._word_count import search, search_sequential
__all__ = ['search', 'search_sequential', 'search_py']
def search_py(path, needle):
total = 0
with open(path, 'r') as f:
for line in f:
words = line.split(' ')
for word in words:
if word == needle:
total += 1
return total