Accessing Collection Items

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.

Finding an item in a list is done by searching the whole list, starting from the first item onwards.

This can be quite slow for big lists.

If you need fast lookup for a list item, use an array.

Accessing an item in an array is practically instant because there's no searching involved.

Here's how you'd get the third element from the array users:

💡 The array position starts from 0, not 1. That means that the 3rd element in an array is at position 2.

Compared to lists, dictionaries are non-sequential. This means that a dictionary item doesn't have a position.

What matters is the key. To extract a value from a dictionary you need to reference its key.

Using the same example as previously, let's extract the name:

To extract the value, we first write the name of the dictionary (my_dog), followed by a dot (.) and then the key (name). This is commonly referred to as dot notation.

Depending on the programming language, you can also extract a value using a key between square brackets:

This is usually referred to as bracket notation.

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