Python - making a function that would add "-" between letters -
i'm trying make function, f(x), add "-" between each letter:
for example:
f("james") should output as:
j-a-m-e-s- i love if use simple python functions new programming. in advance. also, please use "for" function because i'm trying learn.
edit:
yes, want "-" after "s".
also, please use "for" function because i'm trying learn
>>> def f(s): m = s[0] in s[1:]: m += '-' + return m >>> f("james") 'j-a-m-e-s' m = s[0]character @ index 0 assigned variablemfor in s[1:]:iterate second character ,m += '-' + iappend-+ char variablemfinally return value of variable
m
if want - @ last this.
>>> def f(s): m = "" in s: m += + '-' return m >>> f("james") 'j-a-m-e-s-'
Comments
Post a Comment