Hello again, I need assistance on a question - no spoilers, just a direction if you will:
I thought I could increment a slice function --> s1[i+1] but Python doesn't allow that operation.
the output is :
ae
bf
cg
d
How can I get that all on one line? Am I approaching this problem incorrectly?
Thanks in advance.
I thought I could increment a slice function --> s1[i+1] but Python doesn't allow that operation.
Code:
def laceStrings(s1, s2):
"""
s1 and s2 are strings.
Returns a new str with elements of s1 and s2 interlaced,
beginning with s1. If strings are not of same length,
then the extra elements should appear at the end.
"""
length=max(len(s1),len(s2))
i=0
last=0
if len(s1)>len(s2):
last = s1[-1]
length-=1
elif len(s2)>len(s1):
last = s2[-1]
length-=1
else:
length=length
while length >0:
print s1[i]+s2[i]
length-=1
i+=1
if len(s1)>len(s2):
print s1[-1]
elif len(s2)>len(s1):
print s2[-1]
else:
return
s1='abcd'
s2='efg'
laceStrings(s1,s2)
the output is :
ae
bf
cg
d
How can I get that all on one line? Am I approaching this problem incorrectly?
Thanks in advance.
