Use Livebook to open this notebook and explore new ideas.
It is easy to get started, on your machine or the cloud.
# Keyword Lists
A `Keyword` list is a list of key-value pairs that has three special characteristics:
1. Keys must be `Atom`s.
1. The key-value pairs are ordered.
1. Keys can be duplicated.
Here's how to use keyword lists:
```elixir
keyword = [name: "Peter", age: 32, name: "Pietah"]
# Access an element using the bracket notation
keyword[:age] # => 32
# But it will only return the first key
keyword[:name] # => "Peter"
# You can also use a helper function
Keyword.get(keyword, :age) # => 32
# Replace an existing value with a new one
Keyword.replace(keyword, :age, 33)
# => [name: "Peter", age: 33, name: "Pietah"]
# But when you update a duplicate key, it will only keep the new value and remove the rest
Keyword.replace(keyword, :name, "Pieter")
# => [name: "Pieter", age: 32]
# Delete all pairs that have a given key
Keyword.delete(keyword, :name)
# => [age: 32]
# Only delete the first occurrence
Keyword.delete_first(keyword, :name)
# => [age: 32, name: "Pietah"]
```
See source