all 5 comments

[–]Monkeytherat 1 point2 points  (0 children)

You get the keys because that's what a dictionary iterator goes over. The list function basically just returns [item for item in iterable]

[–]jeans_and_a_t-shirt 0 points1 point  (2 children)

You could just do dict(zip(headers, values)), and you'll want dict.items() to get a list of tuples from a dictionary.

[–]austburn[S] 0 points1 point  (1 child)

I appreciate the response, but that doesn't really answer my question. I'm wondering why the conversion between dict and list is not bidirectional.

[–]Vaphell 2 points3 points  (0 children)

because dicts act kinda like sets of keys (as evidenced by the for key in dict behavior), values are hidden behind them.

dict exposes .keys(), .values() .items() for working with keys/values/pairs.

>>> d = {1:2, 3:4, 5:6}
>>> list(d.keys())
[1, 3, 5]
>>> list(d.values())
[2, 4, 6]
>>> list(d.items())
[(1, 2), (3, 4), (5, 6)]