Python Python Collections Slices Slice Functions

Why is this wrong?

I turned the iterables into a list, took the first and last 4, added them together, turned the list into a string, turned the string into an int, then returned the value.
def first_4(something):
    idk = list(something)
    bang = idk[0:4]
    return bang

def first_and_last_4(ladeedaa):
    items = list(ladeedaa)
    first_four_items = items[0:4]
    last_four_items = items[-1:-5:-1]
    new_list = first_four_items + last_four_items
    string_version_of_list = str(new_list)
    values = int(string_version_of_list)
    return values

1 Answer

Steven Parker
Steven Parker
149,196 Points

You're working way to hard! You don't need to do all the conversions, just apply the slice(s) directly to the argument.