Collections

Learn to Code Today!

Learn 10x faster: coding, no-code and data skills. Join millions of users mastering new tech skills and accelerating their career with Enki.
Get started

This is part of “An intro to Coding” series of posts, with content from the Enki app. If you stumbled upon this, you can start from the beginning.

Sometimes a data type is best represented as a collection of one or more data types.

Imagine you're writing a program to model a train.

One way you would represent a train as a data type would be a collection of train car types.

Each train car type can further be a collection of passenger and luggage data types and so on.

Collections don't have to hold the same type.

Think about modeling a shopping bag. It can hold toys, groceries, and clothing for example.

Lists

A List is a data type that represents a sequential collection.

Usually, you can mix elements with different data types in a list, but some languages only let you use one data type in a list.

Lists items commonly have a direction:

Which can also point both ways if needed:

Sometimes we can see lists written using square brackets [ ], with the values separated by commas inside.

The above is a special kind of list called an array.

An array is a list where each item can be accessed based on its position.

Dictionaries

Dictionaries are associative collections that represent key/value pairs.

The name is inspired by our everyday language dictionaries, which are collections of word/definition pairs.

One way to write a dictionary is using curly braces ({ }):

💡 You can leave comments in your code. Usually, single-line comments are marked using //, but some programming languages might use a different way.

In this example, name is the key, and "Artemis" is the value.

About Enki

  • Fully personalized online up-skilling
  • Unlimited AI coaching
  • Designed by Silicon Valley experts

More articles

Meet your AI-enabled coach

Professional athletes have a coach for every aspect of their performance. Why can’t you for your work? Enki’s AI-powered coaching on-demand - combined with state of the art, structured learning content - makes this a reality.
1
1:1 AI Coaching
How do I remove duplicate emails?
Convert the list to a set and back to a list. Sets automatically remove duplicates.
2
Personalized Exercises
3
Interactive practice

Unlock full access to all skills on Enki with a 7-day free trial

Get started