Iterate over collection of tuples


Hi folks,

I am new to Julia and we are developing an open source framework for developing and using energy system optimization models. We are using JuMP. We have all been working mostly with GAMS untill now.

We are using a generic entity-relationship data model and I would like to develop the most efficient/compact way of iterating over a set of tuples (relationships).

For example, I have a set of entities of type e1 and another set of entities of type e2. I define a relationship that relates entities of type e1 to entites of type e2 which will essentially be a collection of pairs of entites of types e1 and e2.

Now I want to iterate over these pairs of entities… so something like

for o1,o2 in rel_e1_to_e2


so what does rel_e1_to_e2 look like and what is the proper syntax of the for loop statement?

Thanks in advance!


Do you mean zip?


As I understand it, zip will take two collections and combine them… i.e. turn 1,2,3,4 and a,b,c,d into:

Instead, I want to create something that contains only specific pairs and then iterate over them. E.g.



Could you give a concrete example where the data structures are defined.

A vector of tuples seems to fit in with what you want but that seems to “easy”?

julia> V = [("a",3), ("b",5)]
2-element Array{Tuple{String,Int64},1}:
 ("a", 3)
 ("b", 5)

julia> for (x, i) in V
           @show x, i
(x, i) = ("a", 3)
(x, i) = ("b", 5)