Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)
There 2 lists with 20 elements each

I want to change the first element of list A with 20º of list B, the 2º element of list A with 19º of list B, and so forth until change the 20º element of list A with 1º of list B.

1 Answer

0 votes
by (36.8k points)

If I get you right, you want to swap the first element of the list A with the last element of list B, then the second element of list A with second last of list B, Then:

l = len(listA)

for i in range(0, l):

    listA[i], listB[(l - 1) - i] = listB[(l - 1) - i], listA[i]

 Improve your knowledge in data science from scratch using Data Scientist

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...