# [ ] review and run example
# the list before Insert
party_list = ["Joana", "Alton", "Tobias"]
print("party_list before: ", party_list)
# the list after Insert
party_list[1] = "Colette"
print("party_list after: ", party_list)
# [ ] review and run example
party_list = ["Joana", "Alton", "Tobias"]
print("before:",party_list)
# modify index value
party_list[1] = party_list[1] + " Derosa"
print("\nafter:", party_list)
# IndexError Example
# [ ] review and run example which results in an IndexError
# if result is NameError run cell above before running this cell
# IndexError trying to append to end of list
party_list[3] = "Alton"
print(party_list)
# [ ] review and run example changes the data type of an element
# replace a string with a number (int)
single_digits = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
print("single_digits: ", single_digits)
print("single_digits[3]: ", single_digits[3], type(single_digits[3]),"\n")
# replace string with an int
single_digits[3] = 3
print("single_digits: ", single_digits)
print("single_digits[3]: ", single_digits[3], type(single_digits[3]))
# [ ] complete "replace items in a list" task
three_num = [16, 71, 43]
print(three_num)
if three_num[0]<16:
three_num[0] = "small"
else:
three_num[0] = "large"
print(three_num)
# [ ] create challenge function
def str_replace(int_list,index):
if int_list[index]<5:
int_list[index] = "small"
else:
int_list[index] = "large"
print(int_list)
str_replace([2,3,8],2)
# [ ] complete coding task described above
three_words = ["Nice","Red","Boots"]
print(three_words)
three_words[0] = three_words[0].upper()
three_words[2] = three_words[2].swapcase()
print(three_words)
# [ ] review and run example
# the list before Insert
party_list = ["Joana", "Alton", "Tobias"]
print("party_list before: ", party_list)
print("index 1 is", party_list[1], "\nindex 2 is", party_list[2], "\n")
# the list after Insert
party_list.insert(1,"Colette")
print("party_list after: ", party_list)
print("index 1 is", party_list[1], "\nindex 2 is", party_list[2], "\nindex 3 is", party_list[3])
# [ ] insert a name from user input into the party_list in the second position (index 1)
party_list = ["Joana", "Alton", "Tobias"]
# [ ] print the updated list
partyname = input("Enter your name to be invited to the party: ")
party_list.insert(1,partyname)
print(party_list)
# [ ] Fix the Error
tree_list = ["oak"]
print("tree_list before =", tree_list)
tree_list.insert(1,"pine")
print("tree_list after =", tree_list)