Python Program To Swap Two Elements In A List Using Indexing

preview_player
Показать описание
Python Program To Swap Two Elements In A List Using Indexing
#ListInPython#ProgrammingWithPython#ProgramSnippets
Рекомендации по теме
Комментарии
Автор

Good explanation however, I have tried your code but the output list contains the p1 element in both p1 and p2 position hence, assigning an variable for the p1 element would help. likewise,

b=a[p1]
a[p1]=a[p2]
a[p2]=b

sowjanyasuresh