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

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,095 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,095 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'