Answers for "how to append a word in list at the beginning"

41

python append to start of list

lst = ["f", "o", "o", "b", "a","r"]
lst.insert(0,"b")
print(lst) # ["b", "f", "o", "o", "b", "a", "r"]
Posted by: Guest on December-09-2021
0

python how to add a string to the beginning of a list

listexample['exampleone', 'examplethree']
listexample.insert(0, 'exampletwo')
print(listexample)
#prints ['exampletwo', 'exampleone', 'examplethree']
#Use the insert() method when you want to add data to the beginning or middle of a list. 
#Take note that the index to add the new element is the first parameter of the method.
Posted by: Guest on April-18-2021

Code answers related to "how to append a word in list at the beginning"

Python Answers by Framework

Browse Popular Code Answers by Language