# Viewing a part of an array as a dictionary

**URL:** <https://discourse.julialang.org/t/viewing-a-part-of-an-array-as-a-dictionary/55233>\
**Category:** General Usage\
**Tags:** dictionary\
**Created:** [February 13, 2021, 10:51pm UTC](https://discourse.julialang.org/t/viewing-a-part-of-an-array-as-a-dictionary/55233 "2021-02-13T22:51:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![circonflexe](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@circonflexe](https://discourse.julialang.org/u/circonflexe)\
**Post date:** [February 13, 2021, 10:51pm UTC](https://discourse.julialang.org/t/viewing-a-part-of-an-array-as-a-dictionary/55233/1 "2021-02-13T22:51:37Z")

</div>

I have an array `array` (actually a `Vector`, to keep it simple), and I want to do work (let’s say call a function `do_work`) on only those values indexed by some set `S` of indices of that vector. This subset has no reason to be an interval. The function `do_work` should, if possible, be written as accepting, as input, any given collection. On the other hand, the nature of the work requires that the indexing set remains `S` (as an example, think “splitting a graph in connected components”); this means that simply passing `array[S]` is not an option since this would reindex to `1:length(S)`.

Does there exist a way to build a “dictionary view” of an array (i.e. something inheriting from `AbstractDict`)? A fixed set of indices is not a problem in my case. I just looked at `Dictionaries.jl`, and I don’t believe that that package includes such a type.

(Really, all the data I need to pass to my `do_work` function is the triple `(S, k->getindex(array,k), (k,v)->setindex!(array,v,k))`, but it would be nice to have a struct encapsulating these and the corresponding index-set guards).

**Edit** I think I found something in `Dictionaries.jl`, I leave the post up in case this is proves useful to someone:

```julia
array=ArrayDictionary([:a,:b,:c,:d])
subarray = view(array, Indices([2,1,4]))
subarray[2] = :replaced

```
