# Best way to implement "enum" like python, c, java?

**URL:** <https://forum.elixirforum.com/t/best-way-to-implement-enum-like-python-c-java/37079>\
**Category:** Questions\
**Tags:** data-structures\
**Created:** [January 26, 2021, 5:32am UTC](https://forum.elixirforum.com/t/best-way-to-implement-enum-like-python-c-java/37079 "2021-01-26T05:32:14Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![eksperimental](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/eksperimental/32/1401_2.png) [@eksperimental](https://forum.elixirforum.com/u/eksperimental)\
**Post date:** [January 27, 2021, 4:02am UTC](https://forum.elixirforum.com/t/best-way-to-implement-enum-like-python-c-java/37079/6 "2021-01-27T04:02:29Z")

</div>

> [@kip](#):
>
> ```elixir
> for {note, midi_value} <- @pitches do
> def pitch(unquote(note)), do: unquote(midi_value)
> def pitch(unquote(midi_value)), do: unquote(note)
> end
> 
> ```

Elegant solution.  
The only one caveat is that since the numbers are not unique you will get a warning saying a previous clause always matches

---

_[View the full topic](https://forum.elixirforum.com/t/best-way-to-implement-enum-like-python-c-java/37079)._
