Note If you don’t know how to solve an problem, or what is the function to be used, you could search on Internet for the answer using the API of the Java programming language. Indeed, since SARL is fully compatible with the Java API, you could use all the types or functions that are defined in this Java API.
Write a SARL program to sum all the items in a list.
Write a SARL program to multiply all the items in a list.
Write a SARL program to get the largest number from a list.
Write a SARL program to count the number of strings from a given list of strings. The string length is 2 or more and the first and last characters are the same.
['abc', 'xyz', 'aba', '1221']
2
Write a SARL program to get a list, sorted in increasing order by the last element in each tuple from a given list of non-empty tuples.
[(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]
[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]
Write a SARL program to remove duplicates from a list.
Write a SARL program to check if a list is empty or not.
Write a SARL program to clone or copy a list.
Write a SARL program to find the list of words that are longer than n from a given list of words.
Write a SARL function that takes two lists and returns true
if they have at least one common member.
Write a SARL program to print a specified list after removing the 0th, 4th and 5th elements.
['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
['Green', 'White', 'Black']
Write a SARL program to generate a 346 3D array whose each element is *
.
Write a SARL program to print the numbers of a specified list after removing even numbers from it.
Write a SARL program to shuffle and print a specified list.
Write a SARL program to generate all permutations of a list in SARL.
Write a SARL program to calculate the difference between the two lists.
Write a SARL program to access the index of a list.
[5, 15, 35, 8, 98]
0 5
1 15
2 35
3 8
4 98
Write a SARL program to convert a list of characters into a string.
Write a SARL program to find the index of an item in a specified list.
Write a SARL program to flatten a shallow list.
[[4], [0, 658, 4, 6], [1, 2, 3]]
[4, 0, 658, 4, 6, 1, 2, 3]
Write a SARL program to append a list to the second list.
Write a SARL program to select an item randomly from a list.
Write a SARL program to check whether two lists are circularly identical.
list1 = [10, 10, 0, 0, 10]
list2 = [10, 10, 10, 0, 0]
Output 1: true
Input 2:
list1 = [10, 10, 0, 10, 0]
list2 = [10, 10, 10, 0, 0]
false
Write a SARL program to find the second smallest number in a list.
Write a SARL program to get unique values from a list.
Write a SARL program to get the frequency of elements in a list.
Write a SARL program to check whether a list contains a sublist.
Write a SARL program that uses the Sieve of Eratosthenes method to compute prime numbers up to a specified number.
Note In mathematics, the sieve of Eratosthenes, one of a number of prime number sieves, is a simple, ancient algorithm for finding all prime numbers up to any given limit.
Write a SARL program to create a list by concatenating a given list with a range from 1 to n.
['p', 'q']
['p1', 'q1', 'p2', 'q2', 'p3', 'q3', 'p4', 'q4', 'p5', 'q5']
Write a SARL program to find common items in two lists.
Write a SARL program to change the position of every n-th value to the (n+1)th in a list.
[0,1,2,3,4,5]
[1, 0, 3, 2, 5, 4]
Write a SARL program to convert a list of multiple integers into a single integer.
[11, 33, 50]
113350
Write a SARL program to split a list based on the first character of a word.
['be', 'have', 'do', 'say', 'get', 'make', 'go', 'know', 'take', 'see', 'come', 'think',
'look', 'want', 'give', 'use', 'find', 'tell', 'ask', 'work', 'seem', 'feel',
'leave', 'call']
{ 'a': ['ask'],
'b': ['be'],
'c': ['come', 'call'],
'd': ['do'],
'f': ['find', 'feel'],
'g': ['get', 'go', 'give'],
'h': ['have'],
'k': ['know'],
'l': ['look', 'leave'],
'm': ['make'],
's': ['say', 'see', 'seem'],
't': ['take', 'think', 'tell'],
'u': ['use'],
'w': ['want', 'work']
}
Write a SARL program to create multiple lists.
1..10
{'1': [], '8': [], '14': [], '5': [], '17': [], '9': [], '2': [], '7': [], '16': [], '19': [], '4': [], '18':
[], '13': [], '3': [], '15': [], '11': [], '20': [], '6': [], '12': [], '10': []}
Write a SARL program to convert a pair of values into a sorted unique array.
[(1, 2), (3, 4), (1, 2), (5, 6), (7, 8), (1, 2), (3, 4), (3, 4), (7, 8), (9, 10)]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Write a SARL program to select the odd items from a list.
Write a SARL program to insert an element before each element of a list.
Write a SARL program to print nested lists (each list on a new line) using the println()
function.
[['assign1', 'assign2'], ['final', 'assign4'], ['exam', 'study']]
assign1 assign2
final assign4
exam study
Write a SARL program to convert a list to a list of maps.
["Black", "Red", "Maroon", "Yellow"], ["#000000", "#FF0000", "#800000", "#FFFF00"]
[{'color_name': 'Black', 'color_code': '#000000'}, {'color_name': 'Red', 'color_code': '#FF0000'}, {'color_name': 'Maroon', 'color_code': '#800000'}, {'color_name': 'Yellow', 'color_code': '#FFFF00'}]
Write a SARL program to split a list every Nth element.
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']
[['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]
Write a SARL program to compute the difference between two lists.
a = ["red", "orange", "green", "blue", "white"]
, b = ["black", "yellow", "green", "blue"]
a
is passed before b
: ['white', 'orange', 'red']
b
is passed before a
: ['black', 'yellow']
Write a SARL program to replace the last element in a list with another list.
[1, 3, 5, 7, 9, 10]
and [2, 4, 6, 8]
[1, 3, 5, 7, 9, 2, 4, 6, 8]
Write a SARL program to check whether the n-th element exists in a given list.
Write a SARL program to insert a given string at the beginning of all items in a list.
[1,2,3,4]
emp
['emp1', 'emp2', 'emp3', 'emp4']
Write a SARL program to iterate over two lists simultaneously.
Write a SARL program to flatten a given nested list structure.
[0, 10, [20, 30], 40, 50, [60, 70, 80], [90, 100, 110, 120]]
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]
Write a SARL program to remove consecutive (following each other continuously) duplicates (elements) from a given list.
[0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4]
Write a SARL program to pack consecutive duplicates of a given list of elements into sublists.
[0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]
[[0, 0], [1], [2], [3], [4, 4], [5], [6, 6, 6], [7], [8], [9], [4, 4]]
Write a SARL program to insert an element at a specified position into a given list.
[1, 1, 2, 3, 4, 4, 5, 1]
[1, 1, 12, 2, 3, 4, 4, 5, 1]
Write a SARL program to extract a given number of randomly selected elements from a given list.
4* Original list: [1, 1, 2, 3, 4, 4, 5, 1]
[4, 4, 1]
Write a SARL program to generate combinations of n distinct objects taken from the elements of a given list.
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2] [1, 3] [1, 4] [1, 5] .... [7, 8] [7, 9] [8, 9]
Write a SARL program to round every number in a given list of numbers and print the total sum multiplied by the length of the list.
[22.4, 4.0, -16.22, -9.1, 11.0, -12.22, 14.2, -5.2, 17.5]
243
Write a SARL program to create a multidimensional list (lists of lists) with zeros. Multidimensional list: [[0, 0], [0, 0], [0, 0]]
.
Write a SARL program to read a square matrix from the command line and print the sum of the matrix’s primary diagonal. Accept the size of the square matrix and elements for each column separated with a space (for every row) as input from the user.
2 3 4
4 5 6
3 4 7
14
Write a SARL program to Zip two given lists of lists.
[[1, 3], [5, 7], [9, 11]]
[[2, 4], [6, 8], [10, 12, 14]]
[[1, 3, 2, 4], [5, 7, 6, 8], [9, 11, 10, 12, 14]]
Write a SARL program to extract specified number of elements from a given list, which follows each other continuously.
[1, 1, 3, 4, 4, 5, 6, 7]
[1, 4]
[0, 1, 2, 3, 4, 4, 4, 4, 5, 7]
[4]
Write a SARL program to compute average of two given lists.
[1, 1, 3, 4, 4, 5, 6, 7]
[0, 1, 2, 3, 4, 4, 5, 7, 8]
3.823529411764706
Write a SARL program to count integers in a given mixed list.
[1, 'abcd', 3, 1.2, 4, 'xyz', 5, 'pqr', 7, -5, -12.22]
Write a SARL program to remove a specified column from a given nested list.
[[1, 2, 3], [2, 4, 5], [1, 1, 1]]
[[2, 3], [4, 5], [1, 1]]
[[1, 2, 3], [-2, 4, -5], [1, -1, 1]]
[[1, 2], [-2, 4], [1, -1]]
Write a SARL program to extract a specified column from a given nested list.
[[1, 2, 3], [2, 4, 5], [1, 1, 1]]
[1, 2, 1]
[[1, 2, 3], [-2, 4, -5], [1, -1, 1]]
[3, -5, 1]
Copyright © 2014-2024 SARL.io, the Original Authors and Main Authors.
Documentation text and medias are licensed under the Creative Common CC-BY-SA-4.0; you may not use this file except in compliance with CC-BY-SA-4.0. You may obtain a copy of CC-BY-4.0.
Examples of SARL code are licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the Apache License. You may obtain a copy of the Apache License.
You are free to reproduce the content of this page on copyleft websites such as Wikipedia.
Generated with the translator docs.generator 0.14.0.