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
.
- Find the 5th element in your list.
- Create a new list containing every other value in your original list.
- 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
.
= ['energy', 'water', 'carbon'] str_list
π Practice 3.
Create a copy of my_list
, which you assigned above.
- Using indexing or list operators, remove the first and last elements of your copied list.
- Sort both the original list and the copied list in reverse order.
- Use the
len()
function and a boolean operator to determine which list is longer.
π Practice 4.
- Create a new list of 10 random floats between 0 and 1 called
rand_list
. - Add
rand_list
andmy_list
together in a new list calledfloat_list
. - 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.