I'd like to substitue '(', ')'
with '[', ']'
in the folliwing list using slicing.
# the raw data
square = ['(', ')', '.', '^', '-']
# the result I want
square = ['[', ']', '.', '^', '-']
Replace with slicing method
In [45]: square[:1] = ['[', ']']
In [46]: square
Out[46]: ['[', ']', ']', '.', '^', '-']
# sliced with wrong index, it should be [:2]
I have to manipulate on the modified square like:
square.remove(']')
Or re-assign to square manually
In [47]: square = ['(', ')', '.', '^', '-']
...: square[:2] = ['[', ']']
In [48]: square
Out[48]: ['[', ']', '.', '^', '-']
During the process, how to reset the modified square
to its unmodified status?