title: What is the simple way to merge named tuples in Python?
body: <p>I want to merge two namedtuples without loosing the key names. If, I just do a merge with '+' operator I am getting a tuple as a result but without the names.</p>
  
  <p>For instance:</p>
  
  <pre><code>n [1]: from collections import namedtuple
  
  In [2]: A = namedtuple("A", "a b c")
  
  In [4]: B = namedtuple("B", "d e")
  
  In [5]: a = A(10, 20, 30)
  
  In [6]: b = B(40, 50)
  
  In [7]: a + b
  Out[7]: (10, 20, 30, 40, 50)
  </code></pre>
  
  <p>As you can see in the above case, the result of a + b has no names associated with them.</p>
  
  <p>But, I am able to achieve it by creating a third namedtuple, which has fields from both A and B.</p>
  
  <pre><code>In [8]: C = namedtuple("C", A._fields + B._fields)
  
  In [9]: C(*(a + b))
  Out[9]: C(a=10, b=20, c=30, d=40, e=50)
  </code></pre>
  
  <p>Is this the right way or is there a better way to do this?</p>