<div dir="ltr">Forgive me if this has been mentioned before (i don't think it has) but how about an option somehow to take the list of **kwargs as an association-list? I am approaching this from a point of view of "why am I putting everything into a hashmap just to iterate over it later", as you can see in the way the namedtuple constructor is implemented:<div>
<br></div><div><a href="http://docs.python.org/2/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields">http://docs.python.org/2/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields</a><br>
</div><div><br></div><div style>This may be rather out-there, and I'm not sure if it'll speed things up much, but I'm guessing iterating over an assoc list is faster than iterating over anything else. Building an assoc list is also probably faster than building anything else and it's also the most easily convertible (either to OrderedDict or unordered dict) since it preserves all information.</div>
<div style><br></div><div style>-Haoyi</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 17, 2013 at 5:07 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 16/05/13 23:50, Ethan Furman wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 05/15/2013 08:16 PM, Steven D'Aprano wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I don't believe it can. Hence, when order is important, you cannot use keyword arguments to provide arguments *even if<br>
kwargs are ordered*. But if you write your function like this:<br>
<br>
def create_element(tag, mapping):<br>
pass<br>
<br>
and call it like this:<br>
<br>
create_element('img', OrderedDict([('alt', 'something'), ('src', 'something.jpg')]))<br>
<br>
then you can get order for free. Yes, it's a little less convenient to use a list of tuples than nice keyword syntax,<br>
but that's a solution that doesn't impose any costs on code that doesn't care about ordering.<br>
</blockquote>
<br>
Which 'free' are you talking about? Because if the solution requires extra typing and extra visual clutter, it's not free.<br>
</blockquote>
<br></div>
Free like a puppy :-)<br>
<br>
You make a good point. Perhaps "free" was a bad choice of words. Rather, let me say that if you need ordered keyword arguments, you can have them *right now* without waiting for the day when you can drop support for everything older that Python 3.4 (or whatever version gives you order-preserving kwargs).<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
<br>
-- <br>
Steven</font></span><div class="HOEnZb"><div class="h5"><br>
______________________________<u></u>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br></div>