Question: 4.[15 points] Define a function swap ends that takes a list and returns the same list but with the first and last elements swapped. E.g.,

 4.[15 points] Define a function swap ends that takes a list

4.[15 points] Define a function swap ends that takes a list and returns the same list but with the first and last elements swapped. E.g., swap_ends "hello"- "oellh" (remember, strings are lists of characters). Use function definition by cases to ensure that swap_ends [ ]-[1 and swap_ends [x]-[x]. (I.e., return empty and singleton lists as is)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!