Skip to content

tushushu/notrust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notrust

Not Rust (or No trust) is a Python iteration tools with rust programming language style.

How to install?

Run pip install git+https://github.com/tushushu/notrust.git to install notrust.

How to build?

  • Run python setup.py bdist_wheel to build the wheel file.
  • Run pip install {wheel file path} to install notrust from the wheel file.

Examples

Word count

import re
from notrust import Iter


words = "I like you, and you like me!"
Iter(re.split("\s|,|!", words))\
.map(lambda x: (x, 1))\
.groupby(lambda x: x[0], lambda x: x[1])\
.map(lambda x: (x[0], sum(x[1])))\
.filter(lambda x: x != ' ')\
.to_dict()

Result:
{'I': 1, 'like': 2, 'you': 2, '': 2, 'and': 1, 'me': 1}

Cumulative sum

from notrust import Iter


arr = [1, 2, 3, 4, 5]
Iter(arr)\
.map(lambda x: [x])\
.reduce(lambda x, y: x + [x[-1] + y[0]])

Result:
[1, 3, 6, 10, 15]

Transpose 2D list

from notrust import Iter


mat = [
    [1, 2, 3], 
    [4, 5, 6], 
    [7, 8, 9]
]
Iter(zip(*mat)).map(list).to_list()

Result:
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]

Find the indexes of all negative numbers

from notrust import Iter


arr = [1, -2, 3, -4, 5]
Iter(arr)\
.zip(range(len(arr)))\
.filter(lambda x: x[0] < 0)\
.map(lambda x: x[1])\
.to_list()

Result:
[1, 3]

Releases

No releases published

Packages

No packages published

Languages