for example:
list = ['a','b','c','d']
i want to insert the letter 'j' in front of the first two strings
which will make the list like this
list = ['ja','jb','c','d']
I know how to append strings into the list but not strings into the items in a list.
You can use list comprehension on a slice and get it done.
list1[0:1] = ['j'+x for x in list1[0:2]]
The output of this will be:
['ja', 'jb', 'c', 'd']
2.1m questions
2.1m answers
60 comments
57.0k users