Write a function Swap(num, n) in Python, which accepts a list num of numbers and n is the number of elements. The function will interchange every alternate value. E.g If the list num contain: [11, 21, 31, 41, 51, 61] Output, [21, 11, 41, 31, 61, 51] What is the answer for this anybody tell this
n=[12,35,9,56,24]
first=n[0]
last=n[-1]
n[0]=last
n[-1]=first
print(n)
Nicely explained all five approaches.
Thanks
Well explained!! Thank you so much
You are welcome!
Wonderful explanation super
Thank you so much
Sor using the tuple method when all the values are assigned to get how are the values changed in my list
in tuple function the values can't change...
NIce explanation
Welcome
Thank you sir
Welcome
what is the meaning of tuple?
Get is tuple
A data structure contained ng multiple arts
Write a function Swap(num, n) in Python, which accepts a list num of numbers and n is the
number of elements. The function will interchange every alternate value. E.g
If the list num contain: [11, 21, 31, 41, 51, 61]
Output, [21, 11, 41, 31, 61, 51]
What is the answer for this anybody tell this
list = [1, 2, 3, 4, 5, 6, 7]
for i in range(len(list)-1):
if i%2 == 0 :
list[i],list[i+1]=list[i+1],list[i]
print(list)
@@malaydhami822 what if item in list are not equal is it work or not tell me