Return to Course Home Page


Practice 1-2: Lists + Indexing

⬅️ Previous Session | 🏠 Course Home | ➑️ Next Session |

πŸ“š Practice 1.

Define a new list of floats with 8 elements called my_list.

  1. Find the 5th element in your list.
  2. Create a new list containing every other value in your original list.
  3. Using slicing and two different methods of indexing, remove the first and last values in your list.

πŸ“š Practice 2.

Create the variable str_list and assign it to the list [β€˜energy’, β€˜water’, β€˜carbon’]. Use indexing to extract the second letter of the third element (β€˜a’) in str_list.

str_list = ['energy', 'water', 'carbon']

πŸ“š Practice 3.

Create a copy of my_list, which you assigned above.

  1. Using indexing or list operators, remove the first and last elements of your copied list.
  2. Sort both the original list and the copied list in reverse order.
  3. Use the len() function and a boolean operator to determine which list is longer.

πŸ“š Practice 4.

  1. Create a new list of 10 random floats between 0 and 1 called rand_list.
  2. Add rand_list and my_list together in a new list called float_list.
  3. Print the result.

πŸ“š Practice 5.

Use the range() function to construct a list of all hundreds (e.g. 100, 200, etc.) between 0 and 1000, inclusive.