Given a variable n
,
If n
is an integer, Return a string with dash '-'
marks before and after each odd integer, but do not begin or end the string with a dash mark. If n
is negative, then the negative sign should be removed.
If n
is not an integer, return an empty value.
Ex:
dashatize(274) -> '2-7-4'
dashatize(6815) -> '68-1-5'
def dashatize(n):
pass
def dashatize(n):
print(n)
if type(n) == int:
n = str(abs(n))
new = ""
for e,i in enumerate(n):
if int(i) % 2 != 0:
if e == 0:
new += "{}-".format(i)
elif e == len(n)-1:
new += "-{}".format(i)
else:
new += "-{}-".format(i)
else:
new += i
if new[-1] == "-": new = new[:-1]
return new.replace("--", "-")
else:
return "None"
def dashatize(num):
num_str = str(num)
for i in ['1','3','5','7','9']:
num_str = num_str.replace(i,'-' + i + '-')
return num_str.strip('-').replace('--','-')