I have to write a function which returns the every alternate element of a tuple using Python. For eg: if input is (1,"hi",2,"hello",5)
; my output should be (1,2,5)
. I got the answer using while loop and [::2]. But when i try for loop, i face error that tuple occupies 1 positional argument but input has 5 positional argument. So, can anyone give me the equivalent for loop function for the while loop function I am attaching?
"https://pastebin.com/embed_js/YkGdiyva"
def oddTuples(aTup):
'''
aTup: a tuple
returns: tuple, every other element of aTup.
'''
# Your Code Here
rTup = ()
index = 0
while index < len(aTup):
rTup += (aTup[index],)
index += 2
return rTup