typing icon indicating copy to clipboard operation
typing copied to clipboard

Specify NamedTuple

Open gvanrossum opened this issue 1 year ago • 1 comments

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 .

gvanrossum avatar Dec 22 '23 02:12 gvanrossum

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)

khushi-98 avatar Jan 24 '24 12:01 khushi-98

This is now complete.

erictraut avatar Mar 09 '24 16:03 erictraut