# Lists

The Lists folder in Blockly contains blocks that can be used to create and manipulate lists. Lists are ordered collections of items. They can be used to store any type of data, including numbers, strings, and even other lists.

Lists are useful in programming because they allow you to store and organize collections of data in a single place and perform operations on collections of data in a more efficient way than if you were to perform the operations on each item individually.&#x20;

<figure><img src="/files/bXZOqcH9JcjwZEFUHh0j" alt=""><figcaption><p>lists blocks</p></figcaption></figure>

### Create a list

<figure><img src="/files/qhi0FsxGKGmxdAX0WUVQ" alt=""><figcaption><p>create a list block</p></figcaption></figure>

With this block, you can create a list. By clicking on the gear icon you can modify the number of items and add as many as you like.&#x20;

### Operations with lists&#x20;

<figure><img src="/files/JzmnnLJ6uX6A88H4klzU" alt=""><figcaption><p>operations wth lists blocks</p></figcaption></figure>

These blocks are useful for operations with lists:&#x20;

* The first block creates a list with a specified value repeated in a chosen number of times.&#x20;
* The second block returns the length of the list associated with it.&#x20;
* The third block has two options :&#x20;

1. *List from text* splits the text into a list of texts, breaking at each delimiter chosen by the programmer.&#x20;
2. *Text from list* joins a list of text into one text, separated by a delimiter chosen by the programmer.&#x20;

* The fourth block returns true if the list is empty, otherwise, it returns false.&#x20;
* The last block can be used as a condition to execute or not a loop.&#x20;

### Sorting a list&#x20;

<figure><img src="/files/q5e3DH8XTyekjhcjr1lJ" alt=""><figcaption><p>sort a list block</p></figcaption></figure>

This is another operation with lists. If lists are collections of items they need to be ordered and this block can sort a copy of a list depending on a numeric or alphabetic order. The list can be sorted in ascending or descending ways.&#x20;

### Other operations with lists

<figure><img src="/files/RzQ89I7HyqEpXWb8rBiT" alt=""><figcaption><p>other operations with lists blocks</p></figcaption></figure>

These are other operations you can find interesting while working on lists:&#x20;

* The first block returns the index of the first or the last occurrence of the item in the list. It returns -1 if the item is not found.&#x20;
* The second block can return, remove or return and remove the item at the specified position.&#x20;
* Instead, the third block can set or insert the item at the specified position. There are several options in order to choose the position, and they are related to the second option:&#x20;

1. \#identify the position of a term. #0 is the first term.&#x20;
2. First is the first term in a list.
3. Last is the last term in a list.
4. Random is a random term in a list.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lessons.mistyrobotics.com/blockly-elements/basic-blocks/lists.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
