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

Garrett Stubblefield
Garrett Stubblefield
6,674 Points

I am unclear of what to do or what is going wrong

see above

instances.py
def String combiner(alist):
    allWords = ""
    allNum = 0
    for one in alist:
        if isinstance(one, String):
            allWords.join(one)
        if isinstance(one, int, float):
            allNum += one
    allWords = allWords.join(allNum)
    return allWords

1 Answer

Spencer Hurrle
Spencer Hurrle
3,128 Points

At first glance, a few hints I can give you

-Python use the keyword str to identify strings. Looks like you've entered String at your first isinstance check.

-Your method name should be lowercase, and Kenneth is planning to call the method combiner. You don't need to add 'String' to the method name, and that is part of what's throwing off the attempt to run this challenge code.

-Concatenation would be fine to join the strings (+= operator). I believe .join can only be used when you have a list full of strings, so it wouldn't be appropriate here. Also, when you use the for loop, you're separating the list to look at one item at a time. At this point, .join would only be seeing one item and I'm not sure how this would be handled by Python, but it seems easier to stick to += here.  Edit: I tried running the program with this .join in the for loop with the workspace. Items don't seem to be added to allWords when you use .join like this

-allWords = allWords.join(allNum)   At this point, allNum is just one item - a float type. You can only use .join on iterables such as lists or tuples. This is another spot where the += operator would work better. Don't forget to convert your allNum float to a string type, though!
Spencer Hurrle
Spencer Hurrle
3,128 Points

Forgive the formatting, I'm unfamiliar with Treehouse's comment editing. Here's another version that says all the same stuff without spaces. If I enter the spaces, it converts to the previous format I entered.

At first glance, a few hints I can give you -Python use the keyword str to identify strings. Looks like you've entered String at your first isinstance check. -Your method name should be lowercase, and Kenneth is planning to call the method combiner. You don't need to add 'String' to the method name, and that is part of what's throwing off the attempt to run this challenge code. -Concatenation would be fine to join the strings (+= operator). I believe .join can only be used when you have a list full of strings, so it wouldn't be appropriate here. Also, when you use the for loop, you're separating the list to look at one item at a time. At this point, .join would only be seeing one item and I'm not sure how this would be handled by Python, but it seems easier to stick to += here. Edit: I tried running the program with this .join in the for loop with the workspace. Items don't seem to be added to allWords when you use .join like this -allWords = allWords.join(allNum) At this point, allNum is just one item - a float type. You can only use .join on iterables such as lists or tuples. This is another spot where the += operator would work better. Don't forget to convert your allNum float to a string type, though!

Garrett Stubblefield
Garrett Stubblefield
6,674 Points

Thank You for your help I finally got it.