package for map a list
Project description
Easy Map Reduce for a list python:
Description
This library was created to allow us to use functional style in a list object in python. It is easier to use functional style when we have for example to deal with a several transformation in our data.
In this little library, we can find most of the function used in a list object but with map or reduce or flatten,... methods. If you are familiar with spark rdd, the behavior of all the methods created in ListMapper object is mostly the same. The difference is that it includes some properties of a python list.
News
Now a doc-string was added to this package, so you can use it and have some example of how to use a method in the object created with ListMapper
Issues:
This Library work only with python version >=3.6. If you attempt to use it with an anterior version, there will be an error occurred in some methods.
How to use this package:
First install this package with pip by doing:
pip install functional-list
Then, you can import ListMapper to create an object:
from functional_list import ListMapper
Example:
Let's make the famous word count with this package. Suppose one have a list of a document comes from a text file, and we load it in a simple list
document =[
"python is good",
"python is better than x",
"python is the best",
]
## Now, let tranform the list to a list mapper
document = ListMapper[str](*document)
res = document.flat_map(lambda x:x.split())\
.map(lambda x:(x,1))\
.reduce_by_key(lambda x,y:x+y)
## result will be:
#List[('than', 1), ('the', 1), ('best', 1),
# ('better', 1), ('good', 1), ('is', 3),
# ('python', 3), ('x', 1)]
# And you have your word count :)
The ListMapper object has also the same behavior as a standard python list.
my_list = ListMapper[int](2, 4, 9, 13, 15, 20)
## Append element
my_list.append(55)
## will give List[2, 4, 9, 13, 15, 20, 55]
## Let make some ordianry transformation
my_list.map(lambda x: x*x)\
.filter(lambda x:x%2==0)\
.reduce(lambda x,y:x+y)
# Give as a result 420
If you want to get the list of the method in this object, you just have to do the next command in python:
dir(ListMapper)
To get the doc-string of a method:
print(my_list.map.__doc__)
In each, method, there is an example of how to use the method.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file functional_list-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: functional_list-0.1.6-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.18 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc5170ec35b1374e784bb43749ecc47211fe5072dc8e597407a337072c248284 |
|
MD5 | 2b83eecdfb9b7882a518bd9c82a39e8c |
|
BLAKE2b-256 | a83d39e2fb07a2a4873ef468e1a57a900a5641eacb28224185420941c027485f |