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](files/puzzles/puzzles-lists.jpg)
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](files/puzzles/puzzles-lists-create.jpg)
The following example hides all 3 objects specified in the list once the user clicks on the cube.
![Creating lists in visual logic editor](files/puzzles/puzzles-lists-create-example.jpg)
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](files/puzzles/puzzles-lists-create-example2.jpg)
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](files/puzzles/puzzles-lists-length.jpg)
Example:
![Calculating list length](files/puzzles/puzzles-lists-length-example.jpg)
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](files/puzzles/puzzles-lists-get-remove.jpg)
Example:
![Getting list item](files/puzzles/puzzles-lists-get-remove-example.jpg)
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](files/puzzles/puzzles-lists-set-insert.jpg)
Example:
![Setting list item](files/puzzles/puzzles-lists-set-insert-example.jpg)
create empty
This puzzle creates a new blank list to be filled with items later.
![Visual programming block to create empty list](files/puzzles/puzzles-lists-create-empty.jpg)
Example:
![Checking if list is empty](files/puzzles/puzzles-lists-create-empty-example.jpg)
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](files/puzzles/puzzles-lists-create-with-item-repeated.jpg)
Example:
![Creating list with repeated element](files/puzzles/puzzles-lists-create-with-item-repeated-example.jpg)
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](files/puzzles/puzzles-lists-reverse.jpg)
Example:
![Using list reverse block](files/puzzles/puzzles-lists-reverse-example.jpg)
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](files/puzzles/puzzles-lists-is-empty.jpg)
Example:
![Script to check if list is empty](files/puzzles/puzzles-lists-is-empty-example.jpg)
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](files/puzzles/puzzles-lists-find.jpg)
Example:
![Script to search elements in the list](files/puzzles/puzzles-lists-find-example.jpg)
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](files/puzzles/puzzles-lists-check-item.jpg)
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](files/puzzles/puzzles-lists-get-sub-list.jpg)
Example:
![Using visual programming to retrieve a sublist](files/puzzles/puzzles-lists-get-sub-list-example.jpg)
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](files/puzzles/puzzles-lists-sort.jpg)
Examples:
![List sorting example](files/puzzles/puzzles-lists-sort-example.jpg)
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](files/puzzles/puzzles-lists-list-text-conversion.jpg)
Example for text splitting into list:
![Script that splits a text into the list](files/puzzles/puzzles-lists-list-text-conversion-example.jpg)
Example for list joining into text:
![Script for joining list into the text](files/puzzles/puzzles-lists-list-text-conversion-example2.jpg)
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!