What would be the best way to reduce the code duplication in the following example. I could only reduce 1st two parts, but I wonder how to make the whole function elegant.
def math_task(data):
answer = []
# raise to the third power
for elem in data:
answer += [elem ** 3]
# take the remainder of the division
for i in range(len(answer)):
answer[i] = answer[i] % 5
# add the original list to the remainder
for i in range(len(answer)):
answer[i] = answer[i] + data[i]
# return the result
return answer
math_task(test_data)
# print(math_task([1, 4, 5, 9]))