Dictionaries

Dictionaries in RuLA are collections of key-value pairs. Each key is unique and maps to a value. Keys are strings, while values can be any type.

Creating Dictionaries

Use curly braces with key: value pairs:

{'name': 'John', 'age': 30}
{'x': 1, 'y': 2, 'z': 3}
{}                                      # Empty dictionary
{'items': ['a', 'b'], 'count': 2}       # Nested list

Accessing Dictionary Values

Access values by their key using square brackets:

person = {'name': 'John', 'age': 30}
person['name']          # Returns 'John'
person['age']           # Returns 30

Dictionary Manipulation

Checking for Keys

person = {'name': 'John', 'age': 30}

'name' in person        # Returns True
'address' in person     # Returns False
'address' not in person # Returns True

Getting All Keys

Counting Entries

Useful Dictionary Functions

Function
Description
Example

Get all keys as a list

{'a': 1, 'b': 2}.keys()['a', 'b']

Number of key-value pairs

COUNT({'a': 1, 'b': 2})2

Dictionary Operations

Working with Lists of Dictionaries

Checking Dictionary Contents

Nested Structures

Dictionaries can contain other complex types:

Last updated

Was this helpful?