Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) 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.

slices.py
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
231,248 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.