>>> hash = '355879ACB6'
>>> hashlist = list(hash)
>>> hashlist.insert(4, '-')
>>> ''.join(hashlist)
'3558-79ACB6'
def ins(a,b,c):
return a[:c]+b+a[c:]
a is original string
b is inserted character
c is position
#with error handling
def ins(a,b,c):
if type(a)!=str:
raise("TypeError: Ins takes first arg as a string.")
elif type(b)!=str:
raise("TypeError: Ins takes second arg as a string.")
elif type(c)!=int:
raise("Type error: Ins takes an int for position")
return a[:c]+b+a[c:]
>>> s[:4] + '-' + s[4:]
'3558-79ACB6'
>>> hash = "355879ACB6"
>>> hash = hash[:4] + '-' + hash[4:]
>>> print(hash)
3558-79ACB6
>>> s='355879ACB6'
>>> s[4:4] = '-'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment