CSC104H1 Lecture Notes - Lecture 17: Substring
Document Summary
Csc104 computational thinking lecture notes 17: list of strings, fibonacci sequence: we want to flatten a many-level list, lists contains many level may like: (list (list bat rat) mouse (list (list cat dog snail) (list dolphin)))) A natural thought is: take a look at each element of the original list, and flatten the ones that need to be flattened. But we can save ourselves effort by not worrying about which ones must be flattened, and make the computer work more instead: make it flatten each element: (define (flatten anything) (cond [(list? anything) (apply append (map flatten anything))] [else (list anything)])) (step parallel (flatten (list 1 (list 2 3) [else (list (list 1 (list 2 3) (list (list 4 5) (list 6))))]): evaluate the question (cond #true (apply append (map statement of the first condition flatten (list 1 (list 2 3) (list (list 4 5) (list 6)))))]