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

I'm not sure why I didn't get the expected output, please help.

I'm not sure if I misread the question but I got the question wrong

instances.py
num_list = []
str_list = []

def combiner(stuff_list):

    for item in stuff_list:
        if isinstance(item, (int, float)) == True:
            num_list.append(item)
        else:
            str_list.append(item)
            continue
    new_str_list = ''.join(str_list)


    for i in range(0, (len(num_list)-1)):
        add_list = num_list[i] + num_list[i+1]

    new_add_list = str(add_list)

    final_list = new_str_list + new_add_list

    new_final_list = str(final_list)

    return new_final_list

1 Answer

Steven Parker
Steven Parker
231,269 Points

The numeric accumulation loop doesn't do what you intended. Luckily, there's a built-in function that will do exactly what is needed:

# replace these lines:
    for i in range(0, (len(num_list)-1)):
        add_list = num_list[i] + num_list[i+1]
# with this:
    add_list = sum(num_list)

That should be enough to pass the challenge, but if you wanted some extra practice there are several other ways this function can be optimized.

thank you for the help, why doesn't the loop that made not work

Steven Parker
Steven Parker
231,269 Points

The loop code shown only adds the last two items.