Skip to content

Commit a1baa13

Browse files
authoredJul 12, 2024··
Merge pull request #278 from hitesh1kumar/patch-4
Create Swap Two Elements in a List
2 parents e1be9db + b4f60f4 commit a1baa13

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎B/Swap Two Elements in a List

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Python3 program to swap elements
2+
# at given positions
3+
4+
# Swap function
5+
def swapPositions(list, pos1, pos2):
6+
7+
list[pos1], list[pos2] = list[pos2], list[pos1]
8+
return list
9+
10+
# Driver function
11+
List = [23, 65, 19, 90]
12+
pos1, pos2 = 1, 3
13+
14+
print(swapPositions(List, pos1-1, pos2-1))

0 commit comments

Comments
 (0)
Please sign in to comment.