Skip to content

2.1 Tutorials on using Dictionary and List data structure

michaelhwn edited this page Jan 5, 2021 · 10 revisions

In this tutorial, you will learn how to use the Dictionary and List blocks. All data returned by CAIT's A.I. blocks are represented by either a dictionary, a list, or a combination of both. Therefore, it is important for you to fully understand how to use these blocks.

Dictionary

A dictionary is a data structure that acts as a collection of key-value pairs. For example, a dictionary called SongsAndNumbers can have the following form:

{
 'Imagine': 'John Lennon',
 'Hey Jude': 'The Beatles',
 'Yesterday': 'The Beatles',
 'Smells Like Teen Spirit': 'Nirvana',
 'One': 1,
 'Two': 2
}

In the above SongsAndNumbers dictionary, the key can be the name of a song, e.g. 'Imaging', and the value is the singer of that song, e.g. 'John Lennon'. Or the key can be the English name of a number, e.g. "One", and the value is the number itself, e.g. 1. This key and value correspondence is called key-value pair, and a dictionary can contain a multiple of these key-value pairs.

Clone this wiki locally