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.


isinstance() method

I understand how to use the isinstance() method to check for if it is a string , float , integer, etc, but I am not sure how to use it to solve the challenge

def combiner(["apple", 5.2, "dog", 8]):

2 Answers

Steven Parker
Steven Parker
215,972 Points

When defining your function, remember that it "takes a single argument, which will be a list". Then inside the function, you'll probably want a loop to go through the items in the list and use "isinstance" to test what kind of thing each one is, and process it based on that determination.

What have you tried? It doesn't look like you've taken any steps.

To solve a problem, you need to break it down into small steps. For example:

  • start with an empty string variable
  • and a number variable set to 0
  • loop over the list
  • for each item in the list
  • if the item is a string
  • add it to the string variable
  • if the item is a number
  • add it to the number variable
  • after the loop,
  • concatenate the number variable with the string variable (you'll have to do something to the number variable first)
  • return the result

Can you try to implement the above in code?