Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,5 +663,8 @@ R.where(spec, Obj(1, 2)) # True
- [ ] xor
- [x] 0.1.2 xprod
- [x] 0.1.2 zip
- [ ] zipObj
- [x] zipObj

It will return a dict.

- [x] 0.1.2 zipWith
1 change: 1 addition & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,5 @@
from .xprod import xprod
# pylint: disable=redefined-builtin
from .zip import zip
from .zipObj import zipObj
from .zipWith import zipWith
8 changes: 8 additions & 0 deletions ramda/zipObj.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .private._curry2 import _curry2


def inner_zipObj(keys, values):
return dict(zip(keys, values))


zipObj = _curry2(inner_zipObj)
26 changes: 26 additions & 0 deletions test/test_zipObj.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import unittest

import ramda as R

"""
https://github.com/ramda/ramda/blob/master/test/zipObj.js
"""


class TestZipObj(unittest.TestCase):
def test_combines_an_array_of_keys_with_an_array_of_values_into_a_single_dict(self):
self.assertEqual({'a': 1, 'b': 2, 'c': 3}, R.zipObj(['a', 'b', 'c'], [1, 2, 3]))

def test_ignores_extra_values(self):
self.assertEqual({'a': 1, 'b': 2, 'c': 3}, R.zipObj(['a', 'b', 'c'], [1, 2, 3, 4, 5, 6, 7]))

def test_ignores_extra_keys(self):
self.assertEqual({'a': 1, 'b': 2, 'c': 3}, R.zipObj(['a', 'b', 'c', 'd', 'e', 'f'], [1, 2, 3]))

def test_last_one_in_wins_when_there_are_duplicate_keys(self):
self.assertEqual({'a': 'LAST', 'b': 2, 'c': 3}, R.zipObj(['a', 'b', 'c', 'a'], [1, 2, 3, 'LAST']))


if __name__ == '__main__':
unittest.main()