I\'m new to Python and can\'t find a way to insert a string into a list without it getting split into individual characters:
>>> list=[\'hello\',\'w
ls=['hello','world']
ls.append('python')
['hello', 'world', 'python']
or (use insert
function where you can use index position in list)
ls.insert(0,'python')
print(ls)
['python', 'hello', 'world']
You have to add another list:
list[:0]=['foo']
>>> li = ['aaa', 'bbb']
>>> li.insert(0, 'wow!')
>>> li
['wow!', 'aaa', 'bbb']
To add to the end of the list:
list.append('foo')
To insert at the beginning:
list.insert(0, 'foo')
Sticking to the method you are using to insert it, use
list[:0] = ['foo']
http://docs.python.org/release/2.6.6/library/stdtypes.html#mutable-sequence-types
best put brackets around foo, and use +=
list+=['foo']