I am trying to make a script where a '-' is put in between all odd digits in a given number (ie 991453 would be 9-9-145-3), but for some reason python wont allow me to insert a str into a list of integers. The error I keep on getting is 'TypeError: not all arguments converted during string formatting'
My code:
def DashInsert(text):
list_int = map(int, list(text))
for i in xrange(len(list_int)-1):
if (list_int[i] % 2 == 1) and (list_int[i+1] % 2 == 1):
print i
list_int.insert(i+1,'-')
return list_int
Here is my actual input and error:
999472
0
Traceback (most recent call last):
File "DashInsert.py", line 17, in
print DashInsert(string)
File "DashInsert.py", line 11, in DashInsert
if (list_int[i] % 2 == 1) and (list_int[i+1] % 2 == 1):
TypeError: not all arguments converted during string formatting
%
is string formatting! – Two-Bit Alchemist