# Noemi Cabrera
# 3 November 2021
# In this assesment, I practiced creating lists, accessing items in a list, adding items to
# the end of a list, inserting items into a list, and deleting items from a list using the
# different method I have learned in module 6.
# I had difficulties with the challenge at the end a bit. I coudn't figure out how to repeatedly
# move each otem in the list created without getting an error. Then, after many tries, using
# a while loop worked for me.
# In this code, I created the days_of_week list and populated it with strings.
# [ ] create and populate list called days_of_week then print it
days_of_week = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
print(days_of_week)
# In this code, I used a for..in loop to print the items that are odd indexes only. For this,
# I used string slicng with a step of 2 starting at index 1.
# [ ] after days_of_week is run above, print the days in the list at odd indexes 1,3,5
for day in days_of_week[1::2]:
print(day)
# [ The variable 'phone_letters' is assigned to a list of strings that contain the letters
# for phone keys 0-9. The list is printed ]
# create and populate list called phone_letters then print it
phone_letters = [" ","","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"]
print(phone_letters)
# The variable "day" is assigned to the index 1 element located in the value assigned to the
# days_of_week list. The item is printed
# [ ] create a variable: day, assign day to "Tuesday" using days_of_week[]
# [ ] print day variable
day = days_of_week[1]
print(day)
# The variable "day" is assigned to the index 5 element located in the value assigned to the
# days_of_week list. The item is printed.
# PART 2
# [ ] assign day to days_of_week index = 5
# [ ] print day
day = days_of_week[5]
print(day)
# In this code, the string "Restday" is added to the days_of_week list by using the .append() method.
# [ ] Make up a new day! - append an 8th day of the week to days_of_week
# [ ] print days_of_week
days_of_week.append("Restday")
print(days_of_week)
# In this code, the string "Tryday" is added to the days_of_week list between 'Wednesday'
# and 'Thrusday' by using the .insert() method. You indicate the index where you want to place
# the new item and then indicate the item, which in this case is 'Tryday'.
# [ ] Make up another new day - insert a new day into the middle of days_of_week between Wed - Thurs
# [ ] print days_of_week
days_of_week.insert(3,"Tryday")
print(days_of_week)
# In this code, the string "Icecreamday" is added to the days_of_week list between 'Friday'
# and 'Saturday' by using the .insert() method. The string is placed at index 6. The new list is printed.
# [ ] Extend the weekend - insert a day between Fri & Sat in the days_of_week list
# [ ] print days_of_week
days_of_week.insert(6,"Icecreamday")
print(days_of_week)
# In this code, the last item (idex of -1) is removed from the days_of_week list and can be returned by using the
# .pop() method. The new list is printed.
# [ ] print days_of_week
# [ ] modified week is too long - pop() the last index of days_of_week & print .pop() value
# [ ] print days_of_week
print(days_of_week)
days_of_week.pop(-1)
print(days_of_week)
# In this code, the item at index 4 is deleted from the the days_of_week list by using the
# del method. The new list is printed.
# [ ] print days_of_week
# [ ] delete (del) the new day added to the middle of the week
# [ ] print days_of_week
print(days_of_week)
del days_of_week[4]
print(days_of_week)
# In this code, the first item (idex of 0 - default) is removed from the days_of_week list
# and can be returned by using the .pop() method. The new list is printed.
# [ ] print days_of_week
# [ ] programmers choice - pop() any day in days_of week & print .pop() value
# [ ] print days_of_week
print(days_of_week)
days_of_week.pop()
print(days_of_week)
# In this code, the function let_to_num() is defined. It accepts 1 argument that can be
# any letter, empty string, etc. Using a while loop, this function checks if the argument
# is found in the phone_letters list. If it's found the dial key will be displayed. If it's
# not found, then the key is added one every time and the string "Not found will display".
# [ ] create let_to_num()
def let_to_num(letter):
key = 0
while key < 10:
if letter in phone_letters[key]:
return key
else:
key = key + 1
return "Not Found"
answer = let_to_num("5")
print("The key is:",answer)
# In this code, the string list is turn into a string. BY using a while loop,all the items
# are removed and can also return by using the .pop() method.This is stored in the variable
# rev, which is used to indicate the item after the index in the .insert method to put all
# items in a new list. The new list, rev_string, is turned in to a string by using the
# .join() method. The starting list and the reversed string is printed.
# [ ] Challenge: write the code for "reverse a string"
string = ["Happy", "Sad", "Excited", "Mad"]
rev_str = []
print("List:", string)
while string:
rev = string.pop(0)
rev_str.insert(0,rev)
print("Reversed string:", ", ".join(rev_str))