title: Pythonic way to convert a dictionary into namedtuple or another hashable dict-like?
body: <p>I have a dictionary like:</p>
  <pre><code>d = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
  </code></pre>
  <p>which I would like to convert to a namedtuple.
  My current approach is with the following code</p>
  <pre><code>namedTupleConstructor = namedtuple('myNamedTuple', ' '.join(sorted(d.keys())))
  nt= namedTupleConstructor(**d)
  </code></pre>
  <p>which produces</p>
  <blockquote>
  <p>myNamedTuple(a=1, b=2, c=3, d=4)</p>
  </blockquote>
  <p>This works fine for me (I think), but am I missing a built-in such as...</p>
  <pre><code>nt = namedtuple.from_dict() ?
  </code></pre>
  <p>UPDATE: as discussed in the comments, my reason for wanting to convert my dictionary to a namedtuple is so that it becomes hashable, but still generally useable  like a dict.</p>
  <p>UPDATE2: 4 years after I've posted this question, <a href="https://stackoverflow.com/a/68947528/1870832">TLK posts a new answer</a> recommending using the dataclass decorator that I think is really great. I think that's now what I would use going forward.</p>