1>>> sentence = ['this','is','a','sentence']
2>>> '-'.join(sentence)
3'this-is-a-sentence'
1list = ['Add', 'Grepper', 'Answer']
2Inline
3> joined = " ".join(list)
4> Add Grepper Answer
5Variable
6> seperator = ", "
7> joined = seperator.join(list)
8> Add, Grepper, Answer
1# example of join() function in python
2
3numList = ['1', '2', '3', '4']
4separator = ', '
5print(separator.join(numList))
1text = ['Python', 'is', 'a', 'fun', 'programming', 'language']
2
3# join elements of text with space
4print(' '.join(text))
5
6# Output: Python is a fun programming language
1# the join method in python is works like
2# it joins the the string that you provide to it to a sequence types(lists etc..)
3flowers = [
4 "Daffodil",
5 "Evening Primrose",
6 "Hydrangea",
7 "Iris",
8 "Lavender",
9 "Sunflower",
10 "Tiger Lilly",
11]
12print(", ".join(flowers))
13
14# what the sbove code does is it joins all the flowers in list by ', '
15# output = Daffodil, Evening Primrose, Hydrangea, Iris, Lavender, Sunflower, Tiger Lilly