A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2019-April/157172.html below:

[Python-Dev] Proposal: dict.with_values(iterable)

[Python-Dev] Proposal: dict.with_values(iterable) [Python-Dev] Proposal: dict.with_values(iterable)Serhiy Storchaka storchaka at gmail.com
Tue Apr 23 13:48:15 EDT 2019
12.04.19 19:17, Inada Naoki пише:
> Maybe, collections.DictBuilder may be another option.  e.g.
> 
>>>> from collections import DictBuilder
>>>> builder = DictBuilder(tuple("abc"))
>>>> builder.build(range(3))
> {"a": 0, "b": 1, "c": 2}

Nitpicking: this is rather a factory than a builder. The difference 
between the patterns is that you create a new builder object for every dict:

     builder = DictBuilder()
     builder['a'] = 0
     builder['b'] = 1
     builder['c'] = 2
     result = builder.build()

and create a fabric only for the whole class of dicts:

     factory = DictFactory(tuple("abc"))  # only once
     ...
     result = factory(range(3))

I like the idea of a factory object more than the idea of the dict method.

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4