Skip to main content

Associates python object with other objects

Project description

pemap

Pemap is simple python library for associating ordinary python object with value. Value for object helps in performing most operations on object and getting more information on it.

Value can be used get items or sort them instead of the object directly. An object with its value forms item and multiple items forms block. Block can also be kept inside item which would result in nested blocks since block may contains another block if that item is used within block.

Value can be any python object.

Install

Enter this to your command-line application:

pip install pemap

Usage

First import pemap to use its functions

import pemap

Creates item which is combination of object with its value. Realise that value can be another type than integer or number. Value and object item can be accessed using methods.

marry_item = pemap.create_item("Marry", 30)
john_item = pemap.create_item("John", 10)
ricky_item = pemap.create_item("Ricky", 40)

marry_item.get_object() # 'Marry'
marry_item.get_value() # 30

#marry_item.set_value(20)
#marry_item.get_value() # 20

After creating items you may consider creating block object to hold the items. Block makes it easy to work with multiple items such as accessing them based on their values.

# List of items to use with block
items = [marry_item, john_item, ricky_item]
# Creates block object containing items
items_block = pemap.create_block(items)

items_block.get_values() # ['Marry', 'John', 'Ricky']
items_block.get_objects() # ['Marry', 'John', 'Ricky']

Block object contain even more methods.

It is possible to have nested blocks in that items of block contain another block. Accessing items within nested block can be hard with previous example. But it can be simple if using pemap.create_deep_block() instead of pemap.create_block() which does not take into account nested blocks.

# Create first block with items
first_block_items = [marry_item, john_item, ricky_item]
first_block = pemap.create_block(items)
# Now create item from block and give value of 300.
first_block_item = pemap.create_item(first_block, 300)

# Create item for second block
first_block_item = pemap.create_item(first_block_item)

# Create ben item and followed by second block.
# Realise that second block contains first block with items.
ben_item = pemap.create_item("Ben", 100)
second_block_items = [ben_item, first_block_item]
second_block = pemap.create_deep_block(second_block_items)

# Underlying objects from first block can be accessed in second block.
# First block has been eliminated but its items remained.
second_block.get_objects() # ['Ben', 'Marry', 'John', 'Ricky']

Block can be converted to other python objects like dictionary, tuple and value queue. This only takes into account block items excluding useful data like block value.

items = [marry_item, john_item, ricky_item]
items_block = pemap.create_block(items)

items_block.to_tuple() 
# ((10, 'John'), (30, 'Marry'), (40, 'Ricky'))
items_block.to_dict() 
# {10: 'John', 30: 'Marry', 40: 'Ricky'}
items_block.to_multi_dict() 
# {10: {'John'}, 30: {'Marry'}, 40: {'Ricky'}}

Most of block methods are available as functions ready to be used on items without creating block object.

items = [marry_item, john_item, ricky_item]
pemap.items_to_tuple(items) 
# ((10, 'John'), (30, 'Marry'), (40, 'Ricky'))
pemap.extract_objects(items)
# ['Marry', 'John', 'Ricky']

License

MIT license

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pemap-0.0.2.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

pemap-0.0.2-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file pemap-0.0.2.tar.gz.

File metadata

  • Download URL: pemap-0.0.2.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.0

File hashes

Hashes for pemap-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b4a20c7f2d59b43f5fdcd6cd9b95466c5ae566cbff096f6fe90b6a32870439ab
MD5 0501a329d284c992afa6e4e1b1544a39
BLAKE2b-256 0c69758a7682722aebe7ddefe174b729e6688f8dd5654ecc0f4c5242c6524f2d

See more details on using hashes here.

File details

Details for the file pemap-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pemap-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.0

File hashes

Hashes for pemap-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d612ccbcaa5a168ffe34045d1e60c6bcdc5b2a770bf58289f2f15a4f34ab9215
MD5 b5a204974b0143d504a41ad5d5b4ce8e
BLAKE2b-256 ef8d5714337a456b82de5707584cc763a98e0e51d7324e9f6384ba22512c6a78

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page