# Replace integer values with another values

**URL:** <https://forum.inductiveautomation.com/t/replace-integer-values-with-another-values/22999>\
**Category:** General Discussion\
**Created:** [March 1, 2019, 6:19pm UTC](https://forum.inductiveautomation.com/t/replace-integer-values-with-another-values/22999 "2019-03-01T18:19:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [March 1, 2019, 6:19pm UTC](https://forum.inductiveautomation.com/t/replace-integer-values-with-another-values/22999/1 "2019-03-01T18:19:17Z")

</div>

This is not Ignition directly question, but more Python question. And there are many Python gurus in this community…

What I want is to replace integer value with another value.  
I have an integer which can have one of 4 values: 1,2,4,8 and I need to replace those with 0,1,2,3.  
I know can do this with regular IF:

```auto
	if postaja1 == 1:
		postaja1 = 0
	elif postaja1 == 2:
		postaja1 = 1
	elif postaja1 == 4:
		postaja1 = 2
	elif postaja1 == 8:
		postaja1 = 3

```

but I’m almost confident that there is a better/shorter/nicer looking way…?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 1, 2019, 6:31pm UTC](https://forum.inductiveautomation.com/t/replace-integer-values-with-another-values/22999/2 "2019-03-01T18:31:24Z")

</div>

`{1: 0, 2: 1, 4: 2, 8: 3}.get(postaja, -1)` is the easiest option; you can keep the dictionary elsewhere if you might need to extend it later. There might be some bit-shifty-hack that I can’t immediately think of that covers this simple case, but extending it might be more difficult.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 1, 2019, 6:32pm UTC](https://forum.inductiveautomation.com/t/replace-integer-values-with-another-values/22999/3 "2019-03-01T18:32:50Z")

</div>

```auto
translations = {
	1: 1,
	2: 3,
	5: 8,
	13: 21
}

value = translations.get(3, value) # some default value

print value

```

edit: dang @paul-griffith beat me

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [March 1, 2019, 6:45pm UTC](https://forum.inductiveautomation.com/t/replace-integer-values-with-another-values/22999/4 "2019-03-01T18:45:37Z")

</div>

> [@paul-griffith](#):
>
> {1: 0, 2: 1, 4: 2, 8: 3}.get(postaja, -1)

I knew it...👍  
Thank you!
