From the course: Learning Julia

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Dictionaries

Dictionaries - Julia Tutorial

From the course: Learning Julia

Start my 1-month free trial

Dictionaries

- [Instructor] Let's wrap up this chapter by learning about Julia dictionaries. A dictionary is a data structure that maps a unique key to a given value and they are useful for scenarios where you need to look things up quickly. Let's go ahead and open up our dicts_start file. So to create a new dictionary, you can use the dict constructor and it looks like this. So I'll have d1 is equal to dict and then I'm going to map some keys to values. So a is going to map using the equal arrow symbol to one, and then b is going to map to two, and then c will map to three. And then I'll just go ahead and print out the dictionary. So when you create a dictionary this way, Julia will infer the types of keys and values. However, you can also explicitly declare these types as well. So to create a dictionary that maps string keys to string values, I can write code that looks like this. So I can declare the dictionary, and then in curly braces, I can have string for keys and strings for values, and…

Contents