I'm fairly new to programming and I'm really stuck in a problem.
Say I have the following list:
a = [2, "**", 2, "@"]
The list might contain more elements.
What I need to do is change positions between "**" and "@", so I would have
a = [2, "@", 2, "**"]
I've been trying to do it with a for loop, using element indexes to perform the change, but the list index is getting out of range.
How could I do it?
Here's my code:
for j in range (len(expression)):
if expression[j] == "**":
if expression[j+2] == "@":
expression[j], expression[j+2] = expression[j+2], expression[j]
print(expression)