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

Dmitriy Ignatiev
PLUS
Dmitriy Ignatiev
Courses Plus Student 6,236 Points

combiner

Why It is woks in local shell but not in treehouse?

instances.py
def combiner(something):
    x = 0
    y = ''
    for item in something:
        if isinstance(item, int):
            x += item
        if isinstance(item, str):
            y += item

    return y + str(x)

3 Answers

nicole lumpkin
PLUS
nicole lumpkin
Courses Plus Student 5,328 Points

Yikes Ankoor Bhagat I actually found two errors that are causing your code to fail. First, you are missing the '.' in the join method. Second, the variable i is not defined and will throw a NameError. If you make these changes your code will pass!

strings = ''.join([s for s in series if isinstance(s, str)])

Nothing is wrong with the TreeHouse grader :) And also, Treehouse is pretty cool. After all, before subscribing to Treehouse I knew nothing about programming, my background is in Kinesiology and I was a personal trainer for 6 years. Based on the training I've received from Treehouse I was able to spot your errors at a glance! So maybe you should hold off before you cancel that subscription...

nicole lumpkin
nicole lumpkin
Courses Plus Student 5,328 Points

Ps. Nice use of the union set operator and list comprehensions :)

Ankoor Bhagat
Ankoor Bhagat
1,098 Points

Hi Nicole, I usually work on Jupyter notebook, I pasted the wrong code here. In Jupyter notebook I had fixed . and i mistakes. I passed the code by making one modification: Using (isinstance, (int, float)) instead of (isinstance(n, int)|isinstance(n, float). Treehouse material is good however their challenge platform does not provide error trace so it is hard to trace where the error is coming from. I joined Treehouse to just learn OOP Python. Thank you.

nicole lumpkin
PLUS
nicole lumpkin
Courses Plus Student 5,328 Points

Hi Tatiana, You are so close! Take a look at Kenneth's sample input:

["apple", 5.2, "dog", 8]

Do you notice a type in the list that's unaccounted for in your code!? :)

Ankoor Bhagat
Ankoor Bhagat
1,098 Points

I am getting correct output but failing in code challenge. Treehouse is lame, regretting subscription. Will cancel subscription before my card is charged again.

def combiner(series):
    strings = ''join([s for s in series if isinstance(i, str)])
    numbers = str(sum([n for n in series if (isinstance(n, int)|isinstance(n, float))]))
    return strings + numbers

>>> combiner(['apple', 5.2, 'dog', 8])
>>> 'appledog13.2'