Python Forum

Full Version: how to convert list into string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I thought that this would be really easy but I'm having problems.
I want to print a list and add the word "and" before the last value

I tried with the .join method:
list=['a','b','c','d']
x=', '
print(x.join(list)))

This worked to print the list values as a string but I have no way to add the word "and".
How should I do this?
Thanks a lot
Shevach
>>> t = [1, 2, 3]
>>> t.insert(-1, 'test')
>>> t
[1, 2, 'test', 3]
Thank you very much.
It is not good practice to use 'list' as name.

In [1]: list('abc')                                                                                    
Out[1]: ['a', 'b', 'c']

In [2]: list=['a','b','c','d']                                                                         

In [3]: list('abc')                                                                                    
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-88aa818ee054> in <module>
----> 1 list('abc')

TypeError: 'list' object is not callable