I'm working through 99 scheme problems and I have a solution for P16 (Drop every N'th element from a list.) using recursion, but I'm trying to practice more functional methods. Is there a clean way to filter by index in mit-scheme?
(display (drop '(a b c d e f g h i j k) 3)))
=> (a b d e g h k)
In Python I could use enumerate:
import string
lst = list(string.ascii_lowercase[:11])
fltr = filter(lambda item: (item[0]+1)%3, enumerate(lst))
mp = map(lambda item: item[1], fltr)
print(list(mp))
=> ['a', 'b', 'd', 'e', 'g', 'h', 'j', 'k']
or list comprehensions
print([value for index, value in enumerate(lst) if (index+1)%3])
=> ['a', 'b', 'd', 'e', 'g', 'h', 'j', 'k']
Thanks!
My solution using @Dogbert 's hint about
zip.