Coder Social home page Coder Social logo

notrust's Introduction

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]

notrust's People

Contributors

tushushu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.