# Understanding DimensionMismatch in list comprehension

**URL:** https://discourse.julialang.org/t/understanding-dimensionmismatch-in-list-comprehension/21382
**Category:** New to Julia
**Created:** [March 2, 2019, 5:41am UTC](https://discourse.julialang.org/t/understanding-dimensionmismatch-in-list-comprehension/21382 "2019-03-02T05:41:45Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)
#### Post date: [March 2, 2019, 9:14am UTC](https://discourse.julialang.org/t/understanding-dimensionmismatch-in-list-comprehension/21382/4 "2019-03-02T09:14:45Z")

</div>

See [this post](https://discourse.julialang.org/t/collecting-zip/20739/2) for a discussion around this, and a workaround if you do need to collect zip:

```julia
function zip_collect(itr)
    itrsize = Base.IteratorSize(itr)
    itrsize isa Base.HasShape && (itrsize = Base.HasLength())
    Base._collect(1:1, itr, Base.IteratorEltype(itr), itrsize)
end

```

Which works like this:

```julia
julia> collect(zip(rand(1:10, 10), 1:2:162))
ERROR: DimensionMismatch("dimensions must match")

julia> zip_collect(zip(rand(1:10, 10), 1:2:162))
10-element Array{Tuple{Int64,Int64},1}:
 (10, 1)
 (3, 3)
 (2, 5)
 (6, 7)
 (1, 9)
 (6, 11)
 (2, 13)
 (3, 15)
 (6, 17)
 (3, 19)

```

**Warning** : The above code uses the internal `Base._collect` method which might not be a great idea in professional projects, since it could disappear or change behavior in a future version of Julia. It might be better to try to solve your problem in another way until the PR linked in the other post has been fixed.

---

_[View the full topic](https://discourse.julialang.org/t/understanding-dimensionmismatch-in-list-comprehension/21382)._
