16. How can we print 2 names using a join? ie) Michael, Lieberman


My code works, I know how to pass the lesson doing both ways, but i would like to know how to use a join so we can separate the names to print two different names so that it Appears --> Michael, Lieberman.

When I use my join it prints M, i, c, h, a, e, lL, i, e, b, e, r, m, a, n which just looks weird.

Any suggestions how I can get it to print Michael, Lieberman?


n = ["Michael", "Lieberman"]
def join_strings(words):
    for i in range(len(words)):
        result += ", ".join(words[i])
    return result

print join_strings(n)


You are on the right track, in fact the only line posing an error would be this one,

Try appending like this,'



@bandit Thanks for your response. When reading your post at first I thought I would fix this in 2 seconds but it's still not accepting my answer. I still can't wrap my head around it after trying several variations. Would you be able to provide the code?



can I see your updated code please


I figured it out. Was over-thinking this. Sometimes the simplest answer is the best.

Final code below...

n = ["Michael", "Lieberman"]

def join_strings(words):
    return (', ').join(words)

print join_strings(n)

will print Michael, Lieberman

PS. This code won't pass the lesson, but wanted to take this lesson one step further


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.