|
1078 | 1078 | julia> collect(values(D))
|
1079 | 1079 | 2-element Vector{Int64}:
|
1080 | 1080 | 2
|
1081 |
| - 3</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractdict.jl#L107-L130">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.pairs" href="#Base.pairs"><code>Base.pairs</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">pairs(IndexLinear(), A) |
1082 |
| -pairs(IndexCartesian(), A) |
1083 |
| -pairs(IndexStyle(A), A)</code></pre><p>An iterator that accesses each element of the array <code>A</code>, returning <code>i => x</code>, where <code>i</code> is the index for the element and <code>x = A[i]</code>. Identical to <code>pairs(A)</code>, except that the style of index can be selected. Also similar to <code>enumerate(A)</code>, except <code>i</code> will be a valid index for <code>A</code>, while <code>enumerate</code> always counts from 1 regardless of the indices of <code>A</code>.</p><p>Specifying <a href="../arrays/#Base.IndexLinear"><code>IndexLinear()</code></a> ensures that <code>i</code> will be an integer; specifying <a href="../arrays/#Base.IndexCartesian"><code>IndexCartesian()</code></a> ensures that <code>i</code> will be a <a href="../arrays/#Base.IteratorsMD.CartesianIndex"><code>CartesianIndex</code></a>; specifying <code>IndexStyle(A)</code> chooses whichever has been defined as the native indexing style for array <code>A</code>.</p><p>Mutation of the bounds of the underlying array will invalidate this iterator.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = ["a" "d"; "b" "e"; "c" "f"]; |
1084 |
| - |
1085 |
| -julia> for (index, value) in pairs(IndexStyle(A), A) |
1086 |
| - println("$index $value") |
1087 |
| - end |
1088 |
| -1 a |
1089 |
| -2 b |
1090 |
| -3 c |
1091 |
| -4 d |
1092 |
| -5 e |
1093 |
| -6 f |
1094 |
| - |
1095 |
| -julia> S = view(A, 1:2, :); |
1096 |
| - |
1097 |
| -julia> for (index, value) in pairs(IndexStyle(S), S) |
1098 |
| - println("$index $value") |
1099 |
| - end |
1100 |
| -CartesianIndex(1, 1) a |
1101 |
| -CartesianIndex(2, 1) b |
1102 |
| -CartesianIndex(1, 2) d |
1103 |
| -CartesianIndex(2, 2) e</code></pre><p>See also <a href="../arrays/#Base.IndexStyle"><code>IndexStyle</code></a>, <a href="../arrays/#Base.axes-Tuple{Any}"><code>axes</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/iterators.jl#L189-L234">source</a></section><section><div><pre><code class="language-none">pairs(collection)</code></pre><p>Return an iterator over <code>key => value</code> pairs for any collection that maps a set of keys to a set of values. This includes arrays, where the keys are the array indices.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a = Dict(zip(["a", "b", "c"], [1, 2, 3])) |
| 1081 | + 3</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractdict.jl#L107-L130">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.pairs" href="#Base.pairs"><code>Base.pairs</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">pairs(collection)</code></pre><p>Return an iterator over <code>key => value</code> pairs for any collection that maps a set of keys to a set of values. This includes arrays, where the keys are the array indices.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a = Dict(zip(["a", "b", "c"], [1, 2, 3])) |
1104 | 1082 | Dict{String, Int64} with 3 entries:
|
1105 | 1083 | "c" => 3
|
1106 | 1084 | "b" => 2
|
|
1127 | 1105 | 3-element Vector{Int64}:
|
1128 | 1106 | 1
|
1129 | 1107 | 2
|
1130 |
| - 3</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractdict.jl#L133-L171">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.merge" href="#Base.merge"><code>Base.merge</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">merge(d::AbstractDict, others::AbstractDict...)</code></pre><p>Construct a merged collection from the given collections. If necessary, the types of the resulting collection will be promoted to accommodate the types of the merged collections. If the same key is present in another collection, the value for that key will be the value it has in the last collection listed. See also <a href="#Base.mergewith"><code>mergewith</code></a> for custom handling of values with the same key.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a = Dict("foo" => 0.0, "bar" => 42.0) |
| 1108 | + 3</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractdict.jl#L133-L171">source</a></section><section><div><pre><code class="language-none">pairs(IndexLinear(), A) |
| 1109 | +pairs(IndexCartesian(), A) |
| 1110 | +pairs(IndexStyle(A), A)</code></pre><p>An iterator that accesses each element of the array <code>A</code>, returning <code>i => x</code>, where <code>i</code> is the index for the element and <code>x = A[i]</code>. Identical to <code>pairs(A)</code>, except that the style of index can be selected. Also similar to <code>enumerate(A)</code>, except <code>i</code> will be a valid index for <code>A</code>, while <code>enumerate</code> always counts from 1 regardless of the indices of <code>A</code>.</p><p>Specifying <a href="../arrays/#Base.IndexLinear"><code>IndexLinear()</code></a> ensures that <code>i</code> will be an integer; specifying <a href="../arrays/#Base.IndexCartesian"><code>IndexCartesian()</code></a> ensures that <code>i</code> will be a <a href="../arrays/#Base.IteratorsMD.CartesianIndex"><code>CartesianIndex</code></a>; specifying <code>IndexStyle(A)</code> chooses whichever has been defined as the native indexing style for array <code>A</code>.</p><p>Mutation of the bounds of the underlying array will invalidate this iterator.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = ["a" "d"; "b" "e"; "c" "f"]; |
| 1111 | + |
| 1112 | +julia> for (index, value) in pairs(IndexStyle(A), A) |
| 1113 | + println("$index $value") |
| 1114 | + end |
| 1115 | +1 a |
| 1116 | +2 b |
| 1117 | +3 c |
| 1118 | +4 d |
| 1119 | +5 e |
| 1120 | +6 f |
| 1121 | + |
| 1122 | +julia> S = view(A, 1:2, :); |
| 1123 | + |
| 1124 | +julia> for (index, value) in pairs(IndexStyle(S), S) |
| 1125 | + println("$index $value") |
| 1126 | + end |
| 1127 | +CartesianIndex(1, 1) a |
| 1128 | +CartesianIndex(2, 1) b |
| 1129 | +CartesianIndex(1, 2) d |
| 1130 | +CartesianIndex(2, 2) e</code></pre><p>See also <a href="../arrays/#Base.IndexStyle"><code>IndexStyle</code></a>, <a href="../arrays/#Base.axes-Tuple{Any}"><code>axes</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/iterators.jl#L189-L234">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.merge" href="#Base.merge"><code>Base.merge</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">merge(d::AbstractDict, others::AbstractDict...)</code></pre><p>Construct a merged collection from the given collections. If necessary, the types of the resulting collection will be promoted to accommodate the types of the merged collections. If the same key is present in another collection, the value for that key will be the value it has in the last collection listed. See also <a href="#Base.mergewith"><code>mergewith</code></a> for custom handling of values with the same key.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a = Dict("foo" => 0.0, "bar" => 42.0) |
1131 | 1131 | Dict{String, Float64} with 2 entries:
|
1132 | 1132 | "bar" => 42.0
|
1133 | 1133 | "foo" => 0.0
|
|
1547 | 1547 | println(x)
|
1548 | 1548 | end
|
1549 | 1549 | foo
|
1550 |
| -7</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/pair.jl#L5-L32">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Pairs" href="#Base.Pairs"><code>Base.Pairs</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">Iterators.Pairs(values, keys) <: AbstractDict{eltype(keys), eltype(values)}</code></pre><p>Transforms an indexable container into a Dictionary-view of the same data. Modifying the key-space of the underlying data may invalidate this object.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/essentials.jl#L26-L31">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../base/">« 基本功能</a><a class="docs-footer-nextpage" href="../math/">数学相关 »</a><div class="flexbox-break"></div><p class="footer-message">📢📢📢 JuliaCN 2022 冬季见面会 报告<a href="https://cn.julialang.org/meetup-website/2022/">征集</a></p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">设置</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">选择主题</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>本文档在<span class="colophon-date" title="2023 十月 21 周六 14:15">2023 十月 21 周六</span>由<a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a>使用1.8.5版本的Julia生成。</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
| 1550 | +7</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/pair.jl#L5-L32">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Pairs" href="#Base.Pairs"><code>Base.Pairs</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">Iterators.Pairs(values, keys) <: AbstractDict{eltype(keys), eltype(values)}</code></pre><p>Transforms an indexable container into a Dictionary-view of the same data. Modifying the key-space of the underlying data may invalidate this object.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/essentials.jl#L26-L31">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../base/">« 基本功能</a><a class="docs-footer-nextpage" href="../math/">数学相关 »</a><div class="flexbox-break"></div><p class="footer-message">📢📢📢 JuliaCN 2022 冬季见面会 报告<a href="https://cn.julialang.org/meetup-website/2022/">征集</a></p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">设置</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">选择主题</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>本文档在<span class="colophon-date" title="2023 十月 21 周六 15:28">2023 十月 21 周六</span>由<a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a>使用1.8.5版本的Julia生成。</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
0 commit comments