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.

Create a list

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.

Operations with lists

These blocks are useful for operations with lists:

  • The first block creates a list with a specified value repeated in a chosen number of times.

  • The second block returns the length of the list associated with it.

  • The third block has two options :

  1. List from text splits the text into a list of texts, breaking at each delimiter chosen by the programmer.

  2. Text from list joins a list of text into one text, separated by a delimiter chosen by the programmer.

  • The fourth block returns true if the list is empty, otherwise, it returns false.

  • The last block can be used as a condition to execute or not a loop.

Sorting a list

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.

Other operations with lists

These are other operations you can find interesting while working on lists:

  • 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.

  • The second block can return, remove or return and remove the item at the specified position.

  • 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:

  1. #identify the position of a term. #0 is the first term.

  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.

Last updated