MCPcopy Create free account
hub / github.com/EntilZha/PyFunctional / dict

Method dict

functional/pipeline.py:1456–1472  ·  view source on GitHub ↗

Converts sequence of (Key, Value) pairs to a dictionary. >>> type(seq([('a', 1)]).dict()) dict >>> seq([('a', 1), ('b', 2)]).dict() {'a': 1, 'b': 2} :param default: Can be a callable zero argument function. When not None, the returned d

(self, default=None)

Source from the content-addressed store, hash-verified

1454 return collections.defaultdict(lambda: default, dictionary)
1455
1456 def dict(self, default=None):
1457 """
1458 Converts sequence of (Key, Value) pairs to a dictionary.
1459
1460 >>> type(seq([('a', 1)]).dict())
1461 dict
1462
1463 >>> seq([('a', 1), ('b', 2)]).dict()
1464 {'a': 1, 'b': 2}
1465
1466 :param default: Can be a callable zero argument function. When not None, the returned
1467 dictionary is a collections.defaultdict with default as value for missing keys. If the
1468 value is not callable, then a zero argument lambda function is created returning the
1469 value and used for collections.defaultdict
1470 :return: dictionary from sequence of (Key, Value) elements
1471 """
1472 return self.to_dict(default=default)
1473
1474 # pylint: disable=too-many-locals
1475 def to_file(

Callers 2

test_to_dictMethod · 0.80
test_dictMethod · 0.80

Calls 1

to_dictMethod · 0.95

Tested by 2

test_to_dictMethod · 0.64
test_dictMethod · 0.64