I try to find every nth item in the list, but I pretty much lost it. Here is my code:
def returnNth(lst, n):
'list ==> list, return every nth element in lst for n > 0'
res = []
for a in lst:
res = res + [a[::n]]
return res
I realized that [[[n]] can be used to search for the result, but I just get the error message that int is not decryptable. For list [1,2,3,4,5,6], returnNth (l, 2) should return [1,3,5] and for list ["dog", "cat", 3, "hamster", True] , returnNth (u, 2) should return ['dog', 3, True] What can I fix this?
source
share