Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,083 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
216,083 Points

The loop code shown only adds the last two items.