typing
typing copied to clipboard
Specify NamedTuple
I don't believe that the behavior of NamedTuple
is sufficiently specified. See e.g. https://discuss.python.org/t/what-are-the-subtyping-rules-for-tuple-t/39837/52 .
Greetings sir, I have tried to solve this at my convenience. Here is the solution:- from typing import NamedTuple, Optional import collections
def create_tuples(name: Optional[str], fields: list, arrays: list):
if name is not None:
itertuple = collections.namedtuple(name, fields, rename=True)
return map(itertuple._make, zip(*arrays))
else:
return zip(*arrays)
This is now complete.