– List Solutions

breakfast = ["Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"]
palindromic = ["Sausage", "Eggs", "Beans", "Beans", "Eggs", "Sausage"]
nums = [1,1,3,3,3,2,2,2,1,1,1,1,4,4,4,4]
letters = ['a', 'a', 'a', 'a', 'b', 'c', 'c', 'a', 'a', 'd', 'e', 'e', 'e', 'e']

def print_list(list):
    for item in list:

def last_element(list):
    return (list[-1])

def last_but_one(list):
    return (list[-2])

# Using reversed function
def my_reverse(list):
    new_list = []
    for item in reversed(list):
    return new_list

# Using for loop
def my_reverse2(list):
    new_list = []
    for i in range (len(list)-1, -1, -1):
    return new_list

# Using list comprehension
def my_reverse3(list): 
    return [item for item in reversed(list)] 

# Using slicing
def my_reverse4(list): 
    return list[::-1]
def is_palindrome(list):
    if list == my_reverse(list):
        return True
        return False

def compress(list):
    new_list = []
    last_item = list[0] + 1 # so first number is different to itself
    for num in list:
        if num != last_item:
        last_item = num
    return new_list

def pack(list):
    pack_list = []
    last_item = list[0]
    word = ""
    for item in list:
        if item == last_item:
            word = word + item
            word = item
        last_item = item
    return pack_list

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s