# Splat inside an array comprehension

**URL:** <https://discourse.julialang.org/t/splat-inside-an-array-comprehension/3473>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 2, 2017, 5:44am UTC](https://discourse.julialang.org/t/splat-inside-an-array-comprehension/3473 "2017-05-02T05:44:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![westleyargentum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/westleyargentum/32/987_2.png) [@westleyargentum](https://discourse.julialang.org/u/westleyargentum)\
**Post date:** [May 2, 2017, 5:44am UTC](https://discourse.julialang.org/t/splat-inside-an-array-comprehension/3473/1 "2017-05-02T05:44:15Z")

</div>

Hey all, embarrassed to say I’ve been a couple releases behind, but I’m starting to write more julia again and loving 0.5

Something I lost track of, however, is array comprehensions that are automatically flattened. Supposing I have an array of Dicts storing ngram info and I want an array all the ngrams from all the Dicts:

```julia
docs = [Dict("pts," => 22, "forc" => 11), Dict("cass" => 72, "iora" => 44)]

```

There used to be comprehensions that used `[...]` and comprehensions that used `{ ... }`, and we could write:

```julia
[collect(keys(doc)) for doc in docs]

```

But I’ve read enough to understand why that’s gone. Unfortunately the closest replacement I’ve found is:

```julia
collect(Base.Iterators.flatten([collect(keys(doc)) for doc in docs]))

```

Which isn’t horrible, but is definitely a mouthful.

I’m sure this has been discussed somewhere I’ve not found, but does something like this make sense:

```julia
[collect(keys(doc))... for doc in docs]

```

Or is there another way I’m missing entirely?

Thanks! Sorry for being so behind the times!

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 2, 2017, 5:48am UTC](https://discourse.julialang.org/t/splat-inside-an-array-comprehension/3473/2 "2017-05-02T05:48:45Z")

</div>

I usually use a nested list comprehension for this sort of thing (in Julia and also in Python):

```julia
julia> [k for doc in docs for k in keys(doc)]
4-element Array{String,1}:
 "pts,"
 "forc"
 "cass"
 "iora"

```

---

<div class="post-metadata">

**Author:** ![westleyargentum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/westleyargentum/32/987_2.png) [@westleyargentum](https://discourse.julialang.org/u/westleyargentum)\
**Post date:** [May 2, 2017, 12:08pm UTC](https://discourse.julialang.org/t/splat-inside-an-array-comprehension/3473/3 "2017-05-02T12:08:41Z")

</div>

Ah, that makes sense, thanks

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [May 2, 2017, 5:04pm UTC](https://discourse.julialang.org/t/splat-inside-an-array-comprehension/3473/4 "2017-05-02T17:04:19Z")

</div>

> [@westleyargentum](#):
>
> [collect(keys(doc))… for doc in docs]

I’ve wished this syntax was supported several times - it’s such a natural extension of splatting. It should be a straight-forward lowering transformation.
