Reputation: 923
I have C++ background and very new to Python. I might be making a simple mistake.
def make_polish(s) :
no_of_pluses = 0
polish_str = []
i = 0
for index in range(len(s)):
print s[index]
if '+' == s[index]:
no_of_pluses = no_of_pluses + 1
if '*' == s[index]:
polish_str[i] = s[index-1] """Index out of range error here."""
i = i + 1
polish_str[i] = s[index+1]
i = i + 1
polish_str[i] = '*'
i = i + 1
return polish_str
print make_polish("3*4")
Upvotes: 1
Views: 62
Reputation: 59604
Your list polish_str
is always empty. You need to do:
polish_str.append(s[index-1])
Instead of:
polish_str[i] = s[index-1] # """Index out of range error here."""
i = i + 1
When you create the list polish_str = []
it's not allocating space for it as it does in C/C++. It's a dynamic data structure.
Upvotes: 8