Ad space (banner)
๐ŸŸฃJulia Lessons
Lesson 44 / 68

Pairing up two arrays (the zip operation)

This lesson covers pairing two arrays with Julia's zip, with the aim of handling related data together.

Combining two corresponding arrays — one of names, one of scores — element by element is called a zip. Julia has a function called exactly that: zip().

The sample code combines the elements at matching positions of names and scores with zip(names, scores) and takes them out one pair at a time with for (name, score) in zip(...).

A common early stumble is what happens when the two arrays are different lengths. zip() stops at the shorter one, so anything left over is simply not in the result.

In professional work, this is a frequently used pattern for looping over several arrays at once.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Julia directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)