Commits

Andriy Kornatskyy  committed 18361a6

Added list_values to collections module.

  • Participants
  • Parent commits 45481a1

Comments (0)

Files changed (1)

File src/wheezy/core/collections.py

     return dict([(key, function(value)) for key, value in dictionary.items()])
 
 
+def list_values(keys, dictionary):
+    """ Returns `dictionary` values orderd by `keys`.
+
+        >>> d = {'1': 1, '2': 2}
+        >>> list_values(['1', '2', '3'], d)
+        [1, 2, None]
+    """
+    return [key in dictionary and dictionary[key] or None for key in keys]
+
+
 def sorted_items(dictionary):
     """ Returns `dictionary` items sorted by key.