Checkpoint 5.40.1.
Write a function called
index_tup
that takes in a tuple of strings, tup_strings
, as a parameter and returns a string consisting of the characters at the zeroth index from the first string, the first index from the second string, the second index from the third string, etc. Add on to the string until the length of the current word is less than or equal to the current index. For example, index_tup(("peppermint", "athlete", "business", "everyone", "rhyme", "athlete"))
should return ptsret
.
Solution.
Write a function called index_tup that takes in a tuple of strings, tup_strings, as a parameter and returns a string consisting of the characters at the zeroth index from the first string, the first index from the second string, the second index from the third string, etc. Add on to the string until the length of the current word is less than or equal to the current index. For example, index_tup(("peppermint", "athlete", "business", "everyone", "rhyme", "athlete")) should return ptsret.
def index_tup(tup):
str1 = ''
index = 0
for word in tup:
if len(word) > index:
str1 += ((word[index]))
index += 1
else:
return str1
return str1