# Clear dict?

**URL:** https://discourse.julialang.org/t/clear-dict/74742
**Category:** New to Julia
**Tags:** question, dictionary, set
**Created:** [January 17, 2022, 9:04am UTC](https://discourse.julialang.org/t/clear-dict/74742 "2022-01-17T09:04:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![unis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/unis/32/19458_2.png) [@unis](https://discourse.julialang.org/u/unis)
#### Post date: [January 17, 2022, 9:04am UTC](https://discourse.julialang.org/t/clear-dict/74742/1 "2022-01-17T09:04:20Z")

</div>

In Python, one may a clear a dict as follows

```julia
d = {1:'a'}
d.clear()

```

In Julia, I’d have expected a similar workflow along the lines of

```julia
d = Dict(1=>'a')
clear!(d)

```

To my surprise, there seems to be no such function clear!(), neither for dicts nor sets. I guess there’s a good reason for this, and likely some best practices to achieve the same outcome. I’d be interested in both. Thanks a lot!

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [January 17, 2022, 9:10am UTC](https://discourse.julialang.org/t/clear-dict/74742/2 "2022-01-17T09:10:03Z")

</div>

It’s called `empty!`.

---

<div class="post-metadata">

### Author: ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)
#### Post date: [January 20, 2022, 5:58am UTC](https://discourse.julialang.org/t/clear-dict/74742/3 "2022-01-20T05:58:33Z")

</div>

```julia
# methodswith(type/module/function)
julia> methodswith(Dict)
[1] serialize(s::Serialization.AbstractSerializer, d::Dict) in Serialization at .
...
[11] empty!(h::Dict{K, V}) where {K, V} in Base at dict.jl:265
...
[30] sizehint!(d::Dict{T}, newsz) where T in Base at dict.jl:232

help?> empty!
search: empty! empty isempty

  empty!(collection) -> collection

  Remove all elements from a collection.

```
