I want a one-dimensional data structure in Python that allows elements to be named, and is also compatible with *args
(and maybe **kwargs
). Does such a thing exist?
# setup idea (doesn't work)
Tuple = namedtuple("Tuple", ["a", "*b", "c"])
t = Tuple(1, 2, 3, 4)
# desired behavior below
print(t.a)
# output:
# 1
print(t.b)
# output:
# [2, 3]
for x in t:
print(x)
# output:
# 1
# 2
# 3
# 4
The structure should also support assignment.
t.c = 2
for x in t:
print(x)
# output:
# 1
# 2
# 3
# 2