Lists

A list is an ordered collection of items, such as a "to do" list or a shopping list. Items in a list may be of any type, and the same value may appear more than once in a list.

Visual programming blocks to work with lists

Contents

Introduction

Lists are very useful when you need to handle multiple items, such as objects, in bulk. Besides that, in a list you can store any kind of information, such as configurable options, properties of similar HTML elements, RGB values, coordinates, etc.

Puzzles Reference

create

This puzzle allows you to create a new list and specify the initial values. Additional inputs are added by dragging an item block from the gray toolbox on the left into the list block.

Visual programming block to create list

The following example hides all 3 objects specified in the list once the user clicks on the cube.

Creating lists in visual logic editor

Lists can be nested (e.g. list of lists), or have no entries specified at any of the positions. In the latter case a null value is automatically put in a missed position.

Nested lists in visual logic editor

length

This puzzle counts the number of items in the specified list. The null values automatically inserted in missed positions will also be counted.

Visual logic block to calulate list length

Example:

Calculating list length

get / remove

This puzzle retrieves (and / or removes) the item from the specified position (items in a list are indexed starting from 0).

Visual programming block to get list item

Example:

Getting list item

set / insert

This puzzle allows you to add items to a list. The set variant replaces the item at a specified position in a list with a different item (the length of the list stays the same). The insert variant adds a new item into the list at the specified position, shifting the item previously at that position (thus increasing the length of the list). Remember that items in a list are indexed starting from 0.

Visual programming block to set list item

Example:

Setting list item

create empty

This puzzle creates a new blank list to be filled with items later.

Visual programming block to create empty list

Example:

Checking if list is empty

create with item repeated

This puzzle creates a new list and initiates all the positions with the same given item. The main difference with the create empty variant is that the list is initialized with a predefined length, and with some initial values.

Block to create list with repeated element

Example:

Creating list with repeated element

reverse

This puzzle creates a new list filled with the items from the original list in reverse order. The original list will not be changed.

Visual logic block to revese a list

Example:

Using list reverse block

is empty

This puzzle checks if a specified list does not contain any items, and returns true in such the case, or false otherwise. For using with Logic puzzles.

Visual logic block to check if list is emtpy

Example:

Script to check if list is empty

find

This puzzle can be used to check whether an item is contained in a list and, if so, where it appears. If the item was found, it returns its position (items in list are indexed starting from 0). If the item was not found, the puzzle returns -1.

Visual programming block to find list elements

Example:

Script to search elements in the list

check item

This puzzle can be used to check whether an item is contained in a list. If the item was found, it returns boolean value true . If the item was not found, the puzzle returns false.

Block to check list item

get sub-list

This puzzle allows a region of list between two specified positions to be extracted as new list (items in list are indexed starting from 0). The original list will not be changed.

Visual logic block to get sublist

Example:

Using visual programming to retrieve a sublist

sort

This puzzle creates a new list filled with the items from the original list sorted in ascending or descending order. The original list will not be changed.

Visual programming block to sort a list

Examples:

List sorting example

list from text / text from list

This puzzle allows you to create a list by splitting some text, or do the opposite - join list items into a line of text.

Visual programming block to create list from text

Example for text splitting into list:

Script that splits a text into the list

Example for list joining into text:

Script for joining list into the text

See Also

Lists store elements by numeric index. If you need a storage with named elements, refer to dictionaries.

Having Troubles with Puzzles?

Seek help on the forums!