Q:

List find and replace

Given the following list of elements:

tmp = ['T', 'h', 'e', '/', ' * ', 's', 'k', 'y', ' * ', 'i', 's', '/', '/', 'b', 'l', 'u', 'e']

I want to :

Replace '*' or '/' by a single space
In case of two consecutive occurrences of '*' or '/', replace those two occurrences by a single space and convert the next character to upper case

Expected Output:

The Sky is Blue
My code works fine but, I was wondering if it can be done in a more pythonic way.
for i in range (len(tmp)):
    if (tmp[i]=='*' and tmp[i+1]=='*') or (tmp[i]=='*' and tmp[i+1]=='/') or (tmp[i]=='/' and tmp[i+1]=='*') or (tmp[i]=='/' and tmp[i+1]=='/'):
        tmp[i+2]=tmp[i+2].upper()

        tmp[i]=""
        tmp[i+1]=" "
        res.append(tmp)
    elif (tmp[i]=='*' or tmp[i]=='/'):
        tmp[i]=" "
        res.append(tmp)
    else:
        res.append(tmp)
new_sentence = ''.join(res[1])

A:

The pythonic way of what you are asking is very simple and just a single line:
tmp = ['a', 'n', '*', '*', ...]
result = "".join(tmp).replace('**', ' ').replace('//', ' ').title().replace('*', ' ').replace('/', ' ').replace('  ', ' ')

Multiple replaces based on the conditions that you required to be replaced
Editing the answer based on the update in question. In order to replace occurrence of a * and a / with space:
import re
tmp_string = "".join(tmp)
result = re.sub(r'[\*|/]{2}', ' ', tmp_string)
result = result.title().replace('*', ' ').replace('/', ' ').replace('  ', ' ')

