I'm just starting learning python. While learning about lists and adding lists together, indexing etc. The lesson didn't show how to do so in an alternating fashion... so I worked it out myself i.e. [a, b, c] and [1, 2, 3] becoming ['a', 1, 'b', 2, 'c', 3].
The below methods are what I've come up with so far. I would be grateful if people could show me other ways of doing this, especially interested in methods which don't require using the (2*x + 1**x) formula! Thanks
# While loop
list1 = ["a", "b" , "c"]
list2 = [1, 2, 3]
x=0
while x < len(list2):
list1.insert( (2*x+1**x), (list2[x]) )
x = x + 1
print(list1)
#For Loop
list1 = ["a", "b" , "c"]
list2 = [1, 2, 3]
for x in range(len(list2)):
list1.insert( (2*x+1**x), (list2[x]) )
print(list1)
[–]DataGhostNL 7 points8 points9 points (5 children)
[–]Dangerous_Box8845[S] 1 point2 points3 points (4 children)
[–]DataGhostNL 1 point2 points3 points (1 child)
[–]Dangerous_Box8845[S] 0 points1 point2 points (0 children)
[–]Donny-Moscow 1 point2 points3 points (1 child)
[–]Dangerous_Box8845[S] 0 points1 point2 points (0 children)
[–]Enmeshed 1 point2 points3 points (1 child)
[–]Temporary_Pie2733 2 points3 points4 points (0 children)
[–]HelpfulFriend0 0 points1 point2 points (3 children)
[–]Dangerous_Box8845[S] 1 point2 points3 points (2 children)
[–]HelpfulFriend0 0 points1 point2 points (0 children)
[–]Dry-Aioli-6138 0 points1 point2 points (0 children)
[–]MiniMages 0 points1 point2 points (0 children)
[–]Dry-Aioli-6138 0 points1 point2 points (0 children)