This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author iritkatriel
Recipients iritkatriel, ludvig.ericson, piotr.dobrogost, terry.reedy
Date 2021-06-20.23:05:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1624230301.61.0.978760927261.issue3276@roundup.psfhosted.org>
In-reply-to
Content
Indeed, as Terry wrote the assumption is that header is a mapping (not necessarily a dict). It is not hard to implement a Multimap that has this API:

import collections.abc

class Multimap(collections.abc.Mapping):
    def __init__(self):
        self.data = collections.defaultdict(list)

    def __getitem__(self, key):
        return self.data[key]

    def __setitem__(self, key, value):
        self.data[key].append(value)

    def __iter__(self):
        yield from self.data

    def items(self):
        for k in list(self.data.keys()):
            for v in list(self.data[k]):
                yield (k,v)

    def __len__(self):
        return sum([len(v) for v in self.data.values()])

mm = Multimap()
mm['1'] = 'a'
mm['1'] = 'aa'
mm['1'] = 'aaa'
mm['2'] = 'b'
mm['3'] = 'c'
mm['3'] = 'cc'
print(f'len = {len(mm)}')
print(f'mm.items() = {list(mm.items())}')

Output:
len = 6
mm.items() = [('1', 'a'), ('1', 'aa'), ('1', 'aaa'), ('2', 'b'), ('3', 'c'), ('3', 'cc')]
History
Date User Action Args
2021-06-20 23:05:01iritkatrielsetrecipients: + iritkatriel, terry.reedy, ludvig.ericson, piotr.dobrogost
2021-06-20 23:05:01iritkatrielsetmessageid: <1624230301.61.0.978760927261.issue3276@roundup.psfhosted.org>
2021-06-20 23:05:01iritkatriellinkissue3276 messages
2021-06-20 23:05:01iritkatrielcreate