Lists & Iteration Exercises
How to use
- Below are code editors that you can use to develop answers to our exercises. We don’t have the resources for a cloud-based compiler so you will have to copy what you write into your blog to interperet the output!
Exercise #1
- Task
- Reverse a list utilizing features of lists and iteration
- Hint: Use two parameters with the range function
- Reverse a list utilizing features of lists and iteration
- Expected Output
-
5 4 3 2 1
-
Hello
list = [1, 2, 3, 4, 5] # Print this list in reverse order
Exercise #2
- Task
- Similar to insertion sort, this algorithm takes an unsorted array and returns a sorted array
- Unlike insertion sort where you iterate through the each element and move the smaller elements to the front, this algorithm starts at the beginning and swaps the position of every element in the array
- Expected Output
- The sorted array from 1-10
list = [9, 8, 4, 3, 5, 2, 6, 7, 1, 0] # Sort this array using bubble sort