Skip to content
Stefano Barbareschi edited this page Oct 8, 2026 · 1 revision

LIST

Okay, but let's say we want to store not just one number or one color. Instead, we want to create multiple values, like grocery items. We could create multiple variables, but that would be time-consuming, and it would be difficult to remember all the variables. That's where a list comes to the rescue.

Think of a list as a container or box that holds multiple things, such as numbers, words, or even other lists.

Example of a List: Let’s say you have a list of your favorite fruits: We can create a variable called grocery and make it a list of grocery items. How does that sound?"

How to create an empty list:

From the following tutorial, you can create an empty list. Along with the tutorial, you can try this on your own as well.

EmptyList.mp4

Create list with:

Okay, now it's time to create a list, add some numbers, and at the same time, we can assign that list to a variable. Check this out!

CreateListWith.mp4

Create list with item (block) repeated (number) times:

Imagine you want to say "Hello!" 5 times. Instead of writing it 5 times, you can use a repeat block and set it to 5.

The computer will then automatically print "Hello!" five times.

In this case, we will show you how to create a list using a variable (here we assigned number 3) and repeat it 7 times.

Cretelist3.mp4

Length of:

The length of a block is the number of items (or elements) inside the list.

Imagine you have a list (array) of grocery items:

grocery = ["apple", "banana", "carrot"]

The list has 3 items in it: "apple", "banana", and "carrot". Now the length of this list is 3 because there are 3 items in it.

lenghtOf.mp4

Is empty:

"is empty" block is a way to check if your list has no items inside it.

Example: Let's say you have an empty list:

grocery = []

This list has no items in it. If you check whether it's empty, the answer will be "True" because there’s nothing inside the list. In this case "True" means "Yes, it is empty".

IsEmpty.mp4

In list [list name] find [operation type] occurrence of item (block):

Imagine you are in a library, and you have a list of books arranged on a shelf.

books = ["Harry Potter", "Lord of the Rings", "Harry Potter", "Sherlock Holmes"]

Now, you want to find the position of "Harry Potter" in the list.

  • Find the first occurrence → The block will return 1 (since "Harry Potter" appears first at position 1).
  • Find the last occurrence → The block will return 3 (since "Harry Potter" appears again at position 3)
  • Find a book that isn’t in the list → If you search for "Percy Jackson," the block will return 0 (because it doesn't exist in the list).

You can find the first or last occurrence of an element in a given list. To do this, first, select the name of the list in the first field. Then, choose whether you want to find the first or last occurrence of the element. Finally, insert a block containing the name of the element you want to find in the selected list. Also, remember that this block will return 0 if the element is not found in the list

LastAndFistInstance.mp4

In list [list name] [operation type] [order by] (block)

Imagine you have a to-do list with tasks you need to complete:

tasks = ["Buy groceries", "Clean the house", "Pay bills", "Walk the dog"]

Now, let's say you want to get or remove a task from the list using the Blockly block.

Example 1: Getting a Task from the List

  • You use the block to retrieve the first task from the list.
  • The block returns: "Buy groceries" (since it’s the first item).

Example 2: Removing a Task from the List

  • You use the block to remove the last task from the list.
  • "Walk the dog" gets removed.

Updated list:

["Buy groceries", "Clean the house", "Pay bills"]

You can get or remove one or more elements from a given list. To do this, first, select the list you want to work on. In the second slot, choose the type of operation you want to perform on the list. In the third slot, specify the order in which you want to work on the list. Lastly, in the fourth slot, insert a block containing the element you want to search for or remove.

INlIst2.mp4

In list [list name] [operation type] [order by] (block) as (block)

You can use this block to set an object at a defined position in the list or insert a new object into a given list at a specific spot. To do this, first, select the name of the list you want to work on in the first slot. Then, choose the type of operation you want to perform in the second slot. Next, specify the order of the operation in the third slot and enter the position where you want to place the new object in the fourth slot. Finally, enter the name of the element in the last slot

INList3.1.mp4

Clone this wiki locally