Pease Helppp! Python - join and list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Pease Helppp! Python - join and list

I seem can't find a way to join all names from the list. Here is my code. def add_surname(n): return n + " surname" names = ["given1", "given2", "given3", "given4", "given5"] full_names = list(map(add_surname, names)) print(full_names) # prints - ['given1 surname', 'given2 surname', 'given3 surname', 'given4 surname', 'given5 surname'] def all_names(): for i in full_names: ", ".join(i) End of my code. It does not have an output for all_names(). What is my mistake? Thank for your help!!

11th Mar 2018, 5:47 PM
Rlt180002
Rlt180002 - avatar
2 Answers
+ 5
Just pass in the list to join() in its entirety instead of each individual element in your all_names function. example: l = ['a', 'b', 'c'] print(', '.join(l)) and then print it.
11th Mar 2018, 5:58 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Thank you! it works now!
11th Mar 2018, 6:10 PM
Rlt180002
Rlt180002 - avatar