from collections import namedtuple
BookPlan = namedtuple('Book', ['size', 'weight'])
books = BookPlan(3, 5), BookPlan(4, 9)
i=0
book={}
while (i<3):
book['size'] = i
book['weight'] = i*5
i=i+1
books=books+BookPlan(**book)
print (books)
I would like to get something like this:
Book(size=3, weight=5), Book(size=4, weight=9), Book(size=1, weight=5), Book(size=2, weight=10)
But in fact I get:
(Book(size=3, weight=5), Book(size=4, weight=9), 1, 5, 2, 10)
It turned out something like concatenation of the namedtuple
and tuple
. Where is my mistake?