Maps

Python supports hashmaps or associative arrays. Every element in a hashmap is associated with a definition or key. Dict is the basic hashmap implementation in Python. The elements in a dict are called values, which are mapped to references known as keys. A dict can be instantiated from an iterable of key-value pairs. This iterable can be a list, tuple, or an iterator, which we will discuss in one of the upcoming sections. The following code snippet shows multiple ways to create a dict:

mydict = dict([(0,1), (1,2), (2,3), (3,4), (4,5)])mydict = dict([[0,1], [1,2], [2,3], [3,4], [4,5]])mydict = {0:1, 1:2, 2:3, 3:4, 4:5}

Elements from a dict can be retrieved by invoking the get method that takes the key as input. Another way is to use ...

Get Practical Time-Series Analysis now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.