<p dir="auto">Try this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="d = Dict([1,2] =&gt; 1.1, [3,2] =&gt; 0.1)
length.(keys(d))"><pre class="notranslate"><code class="notranslate">d = Dict([1,2] =&gt; 1.1, [3,2] =&gt; 0.1)
length.(keys(d))
</code></pre></div>
<p dir="auto">It doesn't work on 0.5 (I've been told it works on master, <a href="https://discourse.julialang.org/t/length-keys-d-does-not-work/913" rel="nofollow">https://discourse.julialang.org/t/length-keys-d-does-not-work/913</a>). Can we pull this into 0.5.1?</p>
<p dir="auto">Currently the very common operation of iterating a Dict's keys in sorted order requires writing the overly verbose <code class="notranslate">sort!(collect(keys(d)))</code>. This could be abbreviated to <code class="notranslate">sort(keys(d))</code> by adding a <code class="notranslate">sort</code> method for <code class="notranslate">KeyIterator</code>, but do we manually add methods for all relevant functions in Base? What about user-defined functions that make sense for general collection-like types? At some point (IIRC) I proposed making <code class="notranslate">KeyIterator</code> and <code class="notranslate">ValueIterator</code> subtypes of <code class="notranslate">AbstractVector</code>, which would make many things "just work". The trouble is that indexing is O(n); however, I believe that something like <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/JeffBezanson/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/JeffBezanson">@JeffBezanson</a>'s <a href="https://github.com/JuliaLang/julia/pull/10116" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/10116/hovercard">ordered dict experiment</a> could make indexing O(1).</p>