---
title: "Dictionaries"
url: https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries
language: python
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Dictionaries

Programming language: Python. Other languages: [C++](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/php.md), [Ruby](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/swift.md).

## Dictionary Syntax and Semantics

A dictionary is an associative array: a collection of key-value pairs in which each key is unique.

For example:

```slice
module M
{
    struct Employee
    {
        long   number;
        string firstName;
        string lastName;
    }

    dictionary<long, Employee> EmployeeMap;
}
```

This definition creates a dictionary named `EmployeeMap` that maps from an employee number to a structure containing the details for an employee.

## Allowable Types for Dictionary Keys and Values

The value type of a dictionary can be any Slice type. However, the key type of a dictionary is limited to one of the following types:

- [Integral](https://docs.zeroc.com/ice/3.8/slice/basic-types/python.md) types (`short`, `int`, `long`)
- [bool](https://docs.zeroc.com/ice/3.8/slice/basic-types/python.md)
- [byte](https://docs.zeroc.com/ice/3.8/slice/basic-types/python.md)
- [string](https://docs.zeroc.com/ice/3.8/slice/basic-types/python.md)
- [enum](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/enumerations/python.md)
- [Structures](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/python.md) containing only fields of legal key types

## Language Mapping

Here is the definition of our EmployeeMap once more:

```slice
dictionary<long, Employee> EmployeeMap;
```

As for sequences, the Python mapping does not create a separate named type for this definition. A Slice dictionary maps to a Python `dict`: in the generated type hints, `EmployeeMap` is `dict[int, Employee]` where Ice creates the dictionary (a proxy return value, a servant parameter) and `Mapping[int, Employee]` where your code supplies it (a proxy parameter, a servant return value). For example:

```py
em = {}

e = Employee()
e.number = 31
e.firstName = "James"
e.lastName = "Gosling"

em[e.number] = e
```
