First, your function name could use a more clear name.
arrayOfInt2string contains a lot of information but none of it makes it clear what the user of function actually is.
decode_str is more clear. Likewise,
array is a bad parameter. The data you're passing is a tuple, not an array. But regardless the type is not a good indicator of what it is.
encoded_str would be clearer. As much as possible, come up with relevant names to make your script easier to read.
You can initialise
b just using
b = . But even better would be to use a list comprehension. A list comprehension collapses a for loop into a single line expression to generate a list. In your case, you can create your whole
b list in just one line like this:
b = [chr(int(a[i:i+2], 16)) for i in range(0, len(a), 2)]
It basically flips the syntax of your
for loop around. You have your expression for each element of
b followed by the syntax of your
for loop. If you really wanted to, both
for loops could be collapsed this way, but that would probably read as too complicated to follow.
s assignment, you can use the
+= operator. It basically says to add whatever is on the right of the operator to the current value of
s. It's shorthand to essentially do what your code already does.
s += ''.join(b.reverse())
''.join(b.reverse()) is not strictly necessary. You can use the slicing operator to reverse it in a shorter line. You've used the slicing operator elsewhere, but you may or may not be aware of the third parameter it takes called the step parameter. It basically tells Python what amount to increment each step by, similar to the third parameter you pass to
range. You can pass a negative value to start at the end and go backwards, so you can flip
b like this: