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 am kind of stuck here

I know I have several problems here.I don't know how do I combine the strings together and it says that I have a TypeError... Explanation for this would be greatly appreciated

instances.py
def combiner(*args):
    lis1 = []
    lis2 = []

    for arg in args:
        if isinstance(arg, str):
            lis1.append(arg)
        elif isinstance(arg, int):
            lis2.append(arg)
    combined = lis1 + sum(lis2)
    return combined

1 Answer

Steven Parker
Steven Parker
221,322 Points

Here's a few hints:

  • the passed argument will be a list, you won't need the "splat" operator
  • as shown in the example, not all numbers will be integers
  • be sure to "join" the list of strings into a single string before combining with the numbers
  • convert the number sum to a string to avoid a TypeError

Can you explain please what do you mean "splat" operator.

Steven Parker
Steven Parker
221,322 Points

"Splat" is just a nickname for the packing operator, or asterisk :point_right: *