# convert int index to alphabet letter

**URL:** <https://forum.ansible.com/t/convert-int-index-to-alphabet-letter/33100>\
**Category:** Ansible Project\
**Created:** [June 5, 2020, 4:15pm UTC](https://forum.ansible.com/t/convert-int-index-to-alphabet-letter/33100 "2020-06-05T16:15:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quentin\_Aveno](https://avatars.discourse-cdn.com/v4/letter/q/e9c0ed/32.png) [@Quentin\_Aveno](https://forum.ansible.com/u/Quentin_Aveno)\
**Post date:** [June 5, 2020, 4:15pm UTC](https://forum.ansible.com/t/convert-int-index-to-alphabet-letter/33100/1 "2020-06-05T16:15:12Z")

</div>

Hi everyone,  
(It’s more a jinja quesion but…)

Is there a way to convert a int to an alphabet letter (1 → a, 2 → b…)

More aesthetic than (with a filter and less useless variables):

`

letters: ‘abcdefghijklmnopqrstuvwxyz’  
index: “{{ groups[‘group1’].index(inventory\_hostname) }}”

index\_letter: “{{ letters[index] }}”  
`

Thanks

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 5, 2020, 6:04pm UTC](https://forum.ansible.com/t/convert-int-index-to-alphabet-letter/33100/2 "2020-06-05T18:04:51Z")

</div>

There is no existing filter that does this, but nothing prevents you  
from writing one...

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 5, 2020, 8:56pm UTC](https://forum.ansible.com/t/convert-int-index-to-alphabet-letter/33100/3 "2020-06-05T20:56:28Z")

</div>

Something like this in your filters file:

def num2let(arg):  
&nbsp;&nbsp;&nbsp;&nbsp;return 'abcdefghijklmnopqrstuvwxyz'[arg]  
def num2let0(arg):  
&nbsp;&nbsp;&nbsp;&nbsp;return 'abcdefghijklmnopqrstuvwxyz'[arg-1]  
class FilterModule(object):  
&nbsp;&nbsp;&nbsp;&nbsp;def filters(self):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'num2let': num2let,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'num2let0': num2let0,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

Then it's:

index: "{{ groups['group1'].index(inventory\_hostname) | num2let0 }}"
