Navigation
Synopsis Library functions for lists.
Description For operators on lists see Values/List.

The following functions are available for lists:
  • delete: Delete an element from a list.
  • distribution: Get the distribution of the elements of the list. That is how often does each element occur in the list?
  • drop: Drop elements from the head of a list.
  • dup: Remove multiple occurrences of elements in a list. The first occurrence remains.
  • getOneFrom: Pick a random element from a list.
  • head: Get the first element(s) from a list.
  • headTail: Split a list in a head and a tail.
  • index: A list of legal index values of a list.
  • indexOf: Index of first occurrence of an element in a list.
  • insertAt: Insert an element at a specific position in a list.
  • intercalate: Join a list of values into a string separated by a separator.
  • isEmpty: Test whether a list is empty.
  • itoString: Convert a list to an indented string.
  • last: Return the last element of a list, if any.
  • lastIndexOf: Return index of last occurrence of elt in lst, or -1 if elt is not found.
  • mapper: Apply a function to all list elements and return list of results.
  • max: Determine the largest element in a list.
  • merge: Merge the elements of two sorted lists into one list.
  • min: Determine the smallest element in a list.
  • mix: Mix the elements of two lists.
  • permutations: Compute all permutations of a list.
  • pop: Pop top element from list, return a tuple.
  • prefix: Return all but the last element of a list.
  • push: Push an element in front of a list.
  • reducer: Apply a function to successive elements of list and combine the results (deprecated).
  • reverse: Reverse a list.
  • size: Determine the number of elements in a list.
  • slice: Compute a sublist of a list.
  • sort: Sort the elements of a list.
  • split: Split a list into two halves.
  • sum: Sum the elements of a list.
  • tail: Get the tail element(s) from a list.
  • take: Get number of elements from the head of a list.
  • takeOneFrom: Remove an arbitrary element from a list, returns the element and the modified list.
  • takeWhile: Take elements from the front of the list as long as a predicate is true.
  • toMap: Convert a list of pairs to a map; first elements are associated with a set of second elements.
  • toMapUnique: Convert a list of tuples to a map; result must be a map.
  • top: Take the top element of a list.
  • toRel: Convert a list to a relation.
  • toSet: Convert a list to a set.
  • toString: Convert a list to a string.
  • unzip: Make a pair (triple) of lists from a list of pairs (triples).
  • upTill: Returns the list 0,1..n-1.
  • zip: Make a list of pairs from two (three) lists of the same length.

Questions
Question [1]. Fill in the missing function name.
(["Saffron", "Luke Skywalker", "Pineapple", "H", "Fig", "Han Solo"], "Saffron") == 0

Question [2]. Fill in the missing function name.
([15, -1, -8, 14, 7], 2, 9) == [15,-1,9,-8,14,7]

Question [3]. Fill in the missing function name.
(";", [5, -14, 5]) == "5;-14;5"

Question [4]. Fill in the missing function name.
([-1, -3, 10]) == [0,1,2]

Question [5]. Fill in the missing function name.
([7, 13]) == 7

Question [6]. Fill in the missing function name.
(["Countess Darling Von Darling", "Lemon", "Luke Skywalker", "Little Bird", "Anise", "S"]) == "S"

Question [7]. Fill in the missing function name.
(["Prince Charming", "Mandarin"]) == {"Mandarin","Prince Charming"}

Question [8]. Fill in the missing function name.
(1, [false, false, true, false, false, false]) == [false]

Question [9]. Fill in the missing function name.
(["K", "Pepper", "Saffron", "S", "Countess Darling Von Darling", "Pomegranate"],2) == ["Countess Darling Von Darling","Pomegranate"]

Question [10]. Fill in the missing function name.
(["Joh Yowza", "Barkley the Dog", "N"]) == <"Joh Yowza",["Barkley the Dog","N"]>

Question [11]. Fill in the missing function name.
([15,-8,-8,15,-19,-16,-4,-8,15]) == [15,-8,-19,-16,-4]

Question [12]. Fill in the missing function name.
([1, -19]) == -19

Question [13]. Fill in the missing function name.
(0, [-16, 2, 4, -4]) == [-16,2,4,-4]

Question [14]. Fill in the missing function name.
([-17, -13, -13]) == [-13,-13,-17]

Question [15]. Fill in the missing function name.
(["R","Luke Skywalker","Mango","Mango","Luke Skywalker","R"], "Mango") == 3

Question [16]. Fill in the missing function name.
(["Cayenne", "V", "Basil"]) == [0,1,2]

Question [17]. Fill in the missing function name.
([-8, 10, -4]) == <-8,[10,-4]>

Question [18].
([18, 1, -11, -7, -10, -17]) == 18

Question [19]. Fill in the missing function name.
([-7, -19], bool(int x){ return x > 0;}) == []

Question [20]. Fill in the missing function name.
(["Luke Skywalker", "Joh Yowza", "Countess Von Backwards"], 1) == ["Luke Skywalker","Countess Von Backwards"]

Question [21]. Fill in the missing function name.
([-10, -9, 6]) == -13

Question [22]. Fill in the missing function name.
([-19, -10, -11, -6], [-7, -6, -10, 4]) == [<-19,-7>,<-10,-6>,<-11,-10>,<-6,4>]

Question [23]. Fill in the missing function name.
([-11, 10, 1, -9]) == [-11,-9,1,10]

Question [24].
Given
int incr(int x) { return x + 1; }
([-15, -10, 4, 15, -11], incr) == [-14,-9,5,16,-10]

Question [25]. Complete this function that tests that a list of words forms a palindrome. A palindrome is a word that is symmetrical
Fill in
import List;
public bool isPalindrome(list[str] words){
  return words == ;
}
and make the following true:
isPalindrome(["a", "b", "b", "a"]) == true;



Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.