+ 2
How can we add 2 elements with insert? How can write index?
8 Réponses
+ 7
this should work and is shorter:
words = ["Python", "fun"]
ind= 1
lst = ['is','so']
words[ind:ind] = lst
print(words)
#(with the help of stack overflow)
+ 8
Something like that:
words = ["Python", "fun"]
index = 1
lst = ['is','so']
for i in lst:
words.insert(index, i)
index += 1
print(words)
#output:
#['Python', 'is', 'so', 'fun']
+ 3
Thanks lothar☺️🙏
+ 2
words = ["Python", "fun"]
index = 1
words.insert(index, "is")
print(words)
I try to say, I want to add"is" and "soo" but it says insert have 2 arguments
+ 2
Probably only solution. But I want to be sure. Thanks to everyone ☺️
+ 1
I try but pyton says : Type Error: insert() takes exactly 2 arguments
+ 1
I mean use insert twice.
0
Python??
2 x insert()
or
2 x append()
or
1 x extend()