Note 1 In SARL, a map is a data structure that is also known as dictionary in other programming languages. This type of data structure maps keys to values.
Note 2 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 script to sort (ascending and descending) a map by value.
Write a SARL script to add a key to a map.
{0: 10, 1: 20}
{0: 10, 1: 20, 2: 30}
Write a SARL script to concatenate the following maps to create a new one.
dic1={1:10, 2:20}
dic2={3:30, 4:40}
dic3={5:50,6:60}
{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
Write a SARL script to check whether a given key already exists in a map.
Write a SARL program to iterate over maps using for loops.
Write a SARL script to generate and print a map that contains a number (between 1 and n) in the form (x, x*x).
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
Write a SARL script to print a map where the keys are numbers between 1 and 15 (both included) and the values are the square of the keys.
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225}
Write a SARL script to merge two SARL maps.
Write a SARL program to sum all the values in a maps.
Write a SARL program to multiply all the values in a map.
Write a SARL program to remove a key from a map.
Write a SARL program to map two lists into a map.
Write a SARL program to sort a given map by key.
Write a SARL program to get the maximum and minimum values of a map.
Write a SARL program to remove duplicated values from the map.
Write a SARL program to check if a map is empty or not.
Write a SARL program to combine two maps by adding values for common keys.
d1 = {'a': 100, 'b': 200, 'c':300}
d2 = {'a': 300, 'b': 200, 'd':400}
{'a': 400, 'b': 400, 'd': 400, 'c': 300}
Write a SARL program to print all distinct values in a map.
[{"V":"S001"}, {"V": "S002"}, {"VI": "S001"}, {"VI": "S005"}, {"VII":"S005"}, {"V":"S009"},{"VIII":"S007"}]
{'S005', 'S002', 'S007', 'S001', 'S009'}
Write a SARL program to create and display all combinations of letters, selecting each letter from a different key in a map.
{'1':['a','b'], '2':['c','d']}
ac
ad
bc
bd
Write a SARL program to find the highest 3 values of corresponding keys in a map.
Write a SARL program to combine values in a list of maps.
[{'item': 'item1', 'amount': 400}, {'item': 'item2', 'amount': 300}, {'item': 'item1', 'amount': 750}]
{'item1': 1150, 'item2': 300}
Write a SARL program to create a map from a string. Track the count of the letters from the string.
w3resource
{'w': 1, '3': 1, 'r': 2, 'e': 2, 's': 1, 'o': 1, 'u': 1, 'c': 1}
Write a SARL program to print a map in table format.
{1: ["Samuel", 21, 'Data Structures'],
2: ["Richie", 20, 'Machine Learning'],
3: ["Lauren", 21, 'OOPS with java'],
}
Samuel 21 Data Structures
Richie 20 Machine Learning
Lauren 21 OOPS with java
Write a SARL program to sort a list alphabetically in a map.
{'n1': [2, 3, 1], 'n2': [5, 1, 2], 'n3': [3, 2, 4]}
{'n1': [1, 2, 3], 'n2': [1, 2, 5], 'n3': [2, 3, 4]}
Write a SARL program to remove spaces from map keys.
Write a SARL program to get the top three items in a shop.
{'item1': 45.50, 'item2':35, 'item3': 41.30, 'item4':55, 'item5': 24}
item4 55
item1 45.5
item3 41.3
Write a SARL program to get the key, value and item in a map.
Write a SARL program to print a map line by line.
Write a SARL program to count the number of items in a map value that is a list.
Write a SARL program to sort items by value in reverse order.
{'Math':81, 'Physics':83, 'Chemistry':87}
[('Chemistry', 87), ('Physics', 83), ('Math', 81)]
Write a SARL program to create a map from two lists without losing duplicate values.
['Class-V', 'Class-VI', 'Class-VII', 'Class-VIII']
and [1, 2, 2, 3]
{'Class-V': {1}, 'Class-VI': {2}, 'Class-VII': {2}, 'Class-VIII': {3}}
Write a SARL program to match key values in two dictionaries.
{'key1': 1, 'key2': 3, 'key3': 2}
and {'key1': 1, 'key2': 2}
{'key1': 1}
is present in both input mapsWrite a SARL program to store map data in a JSON file.
{'students': [{'firstName': 'Nikki', 'lastName': 'Roysden'}, {'firstName': 'Mervin', 'lastName': 'Friedland'}, {'firstName': 'Aron ', 'lastName': 'Wilkins'}], 'teachers': [{'firstName': 'Amberly', 'lastName': 'Calico'}, {'firstName': 'Regine', 'lastName': 'Agtarap'}]}
{'students': [{'firstName': 'Nikki', 'lastName': 'Roysden'}, {'firstName': 'Mervin', 'lastName': 'Friedland'}, {'firstName': 'Aron ', 'lastName': 'Wilkins'}], 'teachers': [{'firstName': 'Amberly', 'lastName': 'Calico'}, {'firstName': 'Regine', 'lastName': 'Agtarap'}]}
Write a SARL program to create a map of keys x, y, and z where each key has as value a list from 11-20, 21-30, and 31-40 respectively. Access the fifth value of each key from the map.
{'x': [11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
'y': [21, 22, 23, 24, 25, 26, 27, 28, 29, 30],
'z': [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]}
15
25
35
x has value [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
y has value [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
z has value [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
Write a SARL program to drop empty items from a given map.
{'c1': 'Red', 'c2': 'Green', 'c3': null}
{'c1': 'Red', 'c2': 'Green'}
Write a SARL program to filter a map based on values.
{'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190}
{'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190}
Write a SARL program to convert more than one list to a nested map.
['S001', 'S002', 'S003', 'S004']
, and ['Adina Park', 'Leyton Marsh', 'Duncan Boyle', 'Saim Richards']
, and [85, 98, 89, 92]
[{'S001': {'Adina Park': 85}}, {'S002': {'Leyton Marsh': 98}}, {'S003': {'Duncan Boyle': 89}}, {'S004': {'Saim Richards': 92}}]
Write a SARL program to filter the height and width of students, which are stored in a map.
{'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}
{'Cierra Vega': (6.2, 70)}
Write a SARL program to verify that all values in a map are the same.
{'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12}
true
false
Write a SARL program to create a map grouping a sequence of key-value pairs into a map of lists.
[('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
{'yellow': [1, 3], 'blue': [2, 4], 'red': [1]}
Write a SARL program to split a given map of lists into lists of maps.
{'Science': [88, 89, 62, 95], 'Language': [77, 78, 84, 80]}
[{'Science': 88, 'Language': 77}, {'Science': 89, 'Language': 78}, {'Science': 62, 'Language': 84}, {'Science': 95, 'Language': 80}]
Write a SARL program to remove a specified map from a given list.
[{'id': '#FF0000', 'color': 'Red'}, {'id': '#800000', 'color': 'Maroon'}, {'id': '#FFFF00', 'color': 'Yellow'}, {'id': '#808000', 'color': 'Olive'}]
#FF0000
from the said list of map: [{'id': '#800000', 'color': 'Maroon'}, {'id': '#FFFF00', 'color': 'Yellow'}, {'id': '#808000', 'color': 'Olive'}]
Write a SARL program to convert string values of a given map into integer/float datatypes.
[{'x': '10', 'y': '20', 'z': '30'}, {'p': '40', 'q': '50', 'r': '60'}]
[{'x': 10, 'y': 20, 'z': 30}, {'p': 40, 'q': 50, 'r': 60}]
[{'x': '10.12', 'y': '20.23', 'z': '30'}, {'p': '40.00', 'q': '50.19', 'r': '60.99'}]
[{'x': 10.12, 'y': 20.23, 'z': 30.0}, {'p': 40.0, 'q': 50.19, 'r': 60.99}]
A SARL map contains List as a value. Write a SARL program to clear the list values in the said map.
{'C1': [10, 20, 30], 'C2': [20, 30, 40], 'C3': [12, 34]}
{'C1': [], 'C2': [], 'C3': []}
A SARL map contains List as a value. Write a SARL program to update the list values in the said map by adding 1 to the scores in Math and substracting 2 to the scores in Physics
{'Math': [88, 89, 90], 'Physics': [92, 94, 89], 'Chemistry': [90, 87, 93]}
{'Math': [89, 90, 91], 'Physics': [90, 92, 87], 'Chemistry': [90, 87, 93]}
Write a SARL program to extract a list of values from a given list of maps.
[{'Math': 90, 'Science': 92}, {'Math': 89, 'Science': 94}, {'Math': 92, 'Science': 88}]
[92, 94, 88]
[{'Math': 90, 'Science': 92}, {'Math': 89, 'Science': 94}, {'Math': 92, 'Science': 88}]
[90, 89, 92]
Write a SARL program to find the length of a map of values.
{1: 'red', 2: 'green', 3: 'black', 4: 'white', 5: 'black'}
{'red': 3, 'green': 5, 'black': 5, 'white': 5}
{'1': 'Austin Little', '2': 'Natasha Howard', '3': 'Alfred Mullins', '4': 'Jamie Rowe'}
{'Austin Little': 13, 'Natasha Howard': 14, 'Alfred Mullins': 14, 'Jamie Rowe': 10}
Write a SARL program to get the depth of a map.
Write a SARL program to access map key’s element by index.
{'physics': 80, 'math': 90, 'chemistry': 86}
0 = physics
1 = math
2 = chemistry
Write a SARL program to convert a map into a list of lists.
{1: 'red', 2: 'green', 3: 'black', 4: 'white', 5: 'black'}
[[1, 'red'], [2, 'green'], [3, 'black'], [4, 'white'], [5, 'black']]
{'1': 'Austin Little', '2': 'Natasha Howard', '3': 'Alfred Mullins', '4': 'Jamie Rowe'}
[['1', 'Austin Little'], ['2', 'Natasha Howard'], ['3', 'Alfred Mullins'], ['4', 'Jamie Rowe']]
Write a SARL program to filter even numbers from a map of values.
{'V': [1, 4, 6, 10], 'VI': [1, 4, 12], 'VII': [1, 3, 8]}
{'V': [4, 6, 10], 'VI': [4, 12], 'VII': [8]}
{'V': [1, 3, 5], 'VI': [1, 5], 'VII': [2, 7, 9]}
{'V': [], 'VI': [], 'VII': [2]}
Write a SARL program to get all combinations of key-value pairs in a given map.
{'V': [1, 4, 6, 10], 'VI': [1, 4, 12], 'VII': [1, 3, 8]}
[{'V': [1, 4, 6, 10], 'VI': [1, 4, 12]}, {'V': [1, 4, 6, 10], 'VII': [1, 3, 8]}, {'VI': [1, 4, 12], 'VII': [1, 3, 8]}]
{'V': [1, 3, 5], 'VI': [1, 5]}
[{'V': [1, 3, 5], 'VI': [1, 5]}]
Write a SARL program to find the specified number of maximum values in a given map.
{'a': 5, 'b': 14, 'c': 32, 'd': 35, 'e': 24, 'f': 100, 'g': 57, 'h': 8, 'i': 100}
['f']
['f', 'i']
['f', 'i', 'g', 'd', 'c']
Write a SARL program to find the shortest list of values for the keys in a given map.
{'V': [10, 12], 'VI': [10], 'VII': [10, 20, 30, 40], 'VIII': [20], 'IX': [10, 30, 50, 70], 'X': [80]}
['VI', 'VIII', 'X']
Write a SARL program to extract values from a given map and create a list of lists from those values.
[{'student_id': 1, 'name': 'Jean Castro', 'class': 'V'}, {'student_id': 2, 'name': 'Lula Powell', 'class': 'V'}, {'student_id': 3, 'name': 'Brian Howell', 'class': 'VI'}, {'student_id': 4, 'name': 'Lynne Foster', 'class': 'VI'}, {'student_id': 5, 'name': 'Zachary Simon', 'class': 'VII'}]
['student_id', 'name', 'class']
: [[1, 'Jean Castro', 'V'], [2, 'Lula Powell', 'V'], [3, 'Brian Howell', 'VI'], [4, 'Lynne Foster', 'VI'], [5, 'Zachary Simon', 'VII']]
['student_id', 'name']
: [[1, 'Jean Castro'], [2, 'Lula Powell'], [3, 'Brian Howell'], [4, 'Lynne Foster'], [5, 'Zachary Simon']]
['name', 'class']
: [['Jean Castro', 'V'], ['Lula Powell', 'V'], ['Brian Howell', 'VI'], ['Lynne Foster', 'VI'], ['Zachary Simon', 'VII']]
Write a SARL program to convert a given list of lists to a map.
[[1, 'Jean Castro', 'V'], [2, 'Lula Powell', 'V'], [3, 'Brian Howell', 'VI'], [4, 'Lynne Foster', 'VI'], [5, 'Zachary Simon', 'VII']]
{1: ['Jean Castro', 'V'], 2: ['Lula Powell', 'V'], 3: ['Brian Howell', 'VI'], 4: ['Lynne Foster', 'VI'], 5: ['Zachary Simon', 'VII']}
Write a SARL program that creates key-value list pairings within a map.
{1: ['Jean Castro'], 2: ['Lula Powell'], 3: ['Brian Howell'], 4: ['Lynne Foster'], 5: ['Zachary Simon']}
[{1: 'Jean Castro', 2: 'Lula Powell', 3: 'Brian Howell', 4: 'Lynne Foster', 5: 'Zachary Simon'}]
Write a SARL program to get the total length of all values in a given map with string values.
{'#FF0000': 'Red', '#800000': 'Maroon', '#FFFF00': 'Yellow', '#808000': 'Olive'}
20
Write a SARL program to check if a specific key and a value exist in a map.
[{'student_id': 1, 'name': 'Jean Castro', 'class': 'V'}, {'student_id': 2, 'name': 'Lula Powell', 'class': 'V'}, {'student_id': 3, 'name': 'Brian Howell', 'class': 'VI'}, {'student_id': 4, 'name': 'Lynne Foster', 'class': 'VI'}, {'student_id': 5, 'name': 'Zachary Simon', 'class': 'VII'}]
Write a SARL program to invert a given map with non-unique hashable values.
{'Ora Mckinney': 8, 'Theodore Hollandl': 7, 'Mae Fleming': 7, 'Mathew Gilbert': 8, 'Ivan Little': 7}
{8: ['Ora Mckinney', 'Mathew Gilbert'], 7: ['Theodore Hollandl', 'Mae Fleming', 'Ivan Little']}
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.