Lists
A list is an ordered collection of items, like a "to-do list" or a "shopping list".
The items in a list can be of any type, and the same value can appear in a list more than once.
Create empty list
The simplest list is an empty list, created with the create empty list block.

Python
[]Create list with
The create list with block lets you give a new list its initial values.

Python
[item0, item1, item2]Create list with repeated item
The create list with item repeated block lets you build a list of the size you want by repeating the specified item.

Python
[item] * timesLength of list
The value of the length of block is the number of items in the list.
The length of an empty list is 0.

Python
len(list)Is empty
The value of the is empty block is true when the input is an empty list, and false otherwise.

Python
not len(list)Find item in list
Finds the position of a specific item in a list.
If the list does not contain that item, the result is 0.

Python
list.index(VALUE) + 1Get / get and remove / remove an item
This block can get, get and remove, or remove an item from a list.
There are several options: first, last, letter #N, and random.

Get
The in list ... get block gets the item at a specific position in a list.
Python
list[0]
list[-1]
list[int(random.random() * len(list))]
list[N - 1]
list[-N]Get and remove
The in list ... get and remove block gets a specific item from a list and removes that item from the list.
Python
list.pop(N - 1) # #
list.pop(-N) # last_#
list.pop(0) # first
list.pop() # last
lists_remove_random_item(list) # random
# random
def lists_remove_random_item(myList):
x = int(random.random() * len(myList))
return myList.pop(x)Remove
The in list ... remove block only removes a specific item from the list.
The plug on the left of the block disappears, so the block can be connected above and below instead.
Python
list.pop(N - 1) # #
list.pop(-N) # last_#
list.pop(0) # first
list.pop() # last
list.pop(int(random.random() * len(list))) # randomSet / insert an item at a position
This block can set or insert an item at the position you want in a list.
There are several options: first, last, letter #N, and random.

Set an item
The in list ... set block replaces the item at the specified position with another item.
Python
list[N - 1] = value # #
list[-N] = value # last_#
list[0] = value # first
list[-1] = value # last
tmp_x = int(random.random() * len(list))
list[tmp_x] = value # randomInsert an item
The in list ... insert at block inserts a new item at the specified position.
Existing items are kept and the length increases by 1.
Python
list.insert(N - 1, value) # #
list.insert(-N, value) # last_#
list.insert(0, value) # first
list.append(value) # last
tmp_x = int(random.random() * len(list))
list.insert(tmp_x, value) # randomGet sub-list
The in list ... get sub-list from ... to ... block extracts a sub-list by specifying a start and an end position.
There are several options: first, last, letter #N, and random.
The original list is not changed by this operation.

Python
# start is the first position (#1)
list[ : N] # #N (1-based)
list[ : -N] # last_#N
list[ : ] # last
# start is last_#N
list[-N : M]
list[-N : -M]
list[-N : ]
# start is first
list[ : N]
list[ : -N]
list[ : ]Get list with an item replaced
The in list ... get list replace block returns a new list in which the item at the specified position has been replaced with another item.
There are several options: first, last, letter #N, and so on.
The original list is not changed by this operation.

Python
# unit = "#"
[value if i == (N - 1) else data for i, data in enumerate(list)]
# unit = "last_#"
[value if i == (len(list) - N) else data for i, data in enumerate(list)]
# unit = "first"
[value if i == 0 else data for i, data in enumerate(list)]
# unit = "last"
[value if i == (len(list) - 1) else data for i, data in enumerate(list)]Split / join text with a delimiter

Make list from text
The make list from text block splits the given text at the delimiter and returns the result as a list.
Python
text.split(delimiter)Make text from list
The make text from list block joins the items of a list into a single piece of text using the delimiter.
Python
delimiter.join(list)Sort list
A block that sorts a list by the criterion you choose.
You can sort numerically or alphabetically, and choose ascending or descending order.
You can also sort alphabetically while ignoring case.

Python
lists_sort(my_list, "NUMERIC", False) # numeric, ascending
lists_sort(my_list, "NUMERIC", True) # numeric, descending
lists_sort(my_list, "TEXT", False) # text, ascending
lists_sort(my_list, "TEXT", True) # text, descending
lists_sort(my_list, "IGNORE_CASE", False) # ignore case, ascending
lists_sort(my_list, "IGNORE_CASE", True) # ignore case, descending
def lists_sort(my_list, type, reverse):
def try_float(s):
try: return float(s)
except: return 0
key_funcs = {
"NUMERIC": try_float,
"TEXT": str,
"IGNORE_CASE": lambda s: str(s).lower()
}
key_func = key_funcs[type]
list_cpy = list(my_list)
return sorted(list_cpy, key=key_func, reverse=reverse)Reverse list
A block that reverses the order of the elements in a list.

Python
list(reversed(my_list))