Skip to content

Apply a map-like function over a Python dictionary and return a new dictionary with the same keys and its values evaluated.

Notifications You must be signed in to change notification settings

ulisesojeda/dictionary_map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

12 Commits

Repository files navigation

Build Status PyPI version Dictionary Mapping

Apply a map-like function over a Python dictionary and return a new dictionary with the same keys and its values mapped.

Installation

$ pip install dict-map

API

dict_map(func,value,deep)
  • func
    Typefunction
    Mapping function

  • value
    Typedictionary
    Dictionary to map

  • deep[False]
    TypeBoolean
    Recurse over nested dictionaries

How to use

importdict_mapasdict_map
value={2:2,3:3,4:{5:5,6:6}}
func=lambdax:x**2
print(dict_map.dict_map(func,value,False))
#{2: 4, 3: 9, 4: {5: 5, 6: 6}}
print(dict_map.dict_map(func,value,True))
#{2: 4, 3: 9, 4: {5: 25, 6: 36}}

Notes

Inspired bybrowser-object-map

MIT Licensed

Copyright (c) 2017 Ulises Ojeda

About

Apply a map-like function over a Python dictionary and return a new dictionary with the same keys and its values evaluated.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages