Practice: Lists#
1: list of numbers#
a = 15
b = 2
c = 10
d = 13
e = 18
f = 22
g = 19
h = 25
1A: Make the list and check it#
Put these into a list and name it numbers
.
How long is the list?
Get the 3rd item
Write a function to get the item from a user-defined position, but include a check to make sure you don’t try to get something from a position that doesn’t exist in the list!
1B: Modify the list#
Add the number 32 to the beginning of numbers
Add the number 13 to the end of numbers
Sort numbers
in ascending order.
Sort the list again (in reverse numeric order, from biggest to smallest), but keep the old list unchanged! Name the new list big_to_small
. Show the first item from both lists.
1C: Math#
Get the smallest and largest numbers from numbers
Compute the average
2: list of strings#
name1 = "Kumiyo"
name2 = "Naielia"
name3 = "Charlie"
name4 = "Juan"
name5 = "Renee"
name6 = "Kumiyo"
name7 = "Frank"
name8 = "Charlie"
name9 = "Kumiyo"
name10 = "Narges"
name11 = "Kumiyo"
2A: make and inspect the list#
Put these into a list and name it people
.
Grab the first 4 people off the list
Grab the last 5 people off the list
How many people are named “Charlie”? How about “Kumiyo”?
2B: Modify the list#
Add three people named “Niklas” to the list of people
.
Sort the list in reverse alphabetical order, but keep the original list untouched! Name the new list sortedPeople
.