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

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

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

2 Answers

Steven Parker
Steven Parker
231,248 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?