-1

I'm trying to merge elements in a list, into one single element back into the list.

For instance I have a list:

fruits = ['apple', 'orange', 'grape']

How do I merge all of them to become, let's say:

fruits = ['apple orange grape']

or

fruits = ['appleorangegrape']

or even

fruits ['apple, orange, grape']

Thank you in advance!!

So far thought about concat(), but it works for list to list, not for combining elements.

1 Answers1

0
fruits = ['apple', 'orange', 'grape']

fruits_str = ' '.join(fruits)
print(fruits_str) # for 'apple orange grape'

fruits_str = ''.join(fruits)
print(fruits_str)  # for 'appleorangegrape'

fruits_str = ', '.join(fruits)
print(fruits_str)  # for 'apple, orange, grape'