8000 Create swapalternate · khalid-codes/python-coding-ninja@1122771 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1122771

Browse files
authored
Create swapalternate
1 parent a1a3d53 commit 1122771

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Arrays&list/swapalternate

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def swap(li,n):
2+
length=len(li)
3+
if n%2==0:
4+
for i in range(0,length,2):
5+
li[i],li[i+1]=li[i+1],li[i]
6+
else:
7+
for i in range(0,length-1,2):
8+
li[i],li[i+1]=li[i+1],li[i]
9+
def printlist(li,n):
10+
for i in range(n):
11+
print(li[i],end=" ")
12+
print()
13+
num=int(input())
14+
for test in range(num):
15+
N=int(input())
16+
li1=[int(x) for x in input().split()]
17+
swap(li1,N)
18+
printlist(li1,N)
19+

0 commit comments

Comments
 (0)
0