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 trialDmitriy Ignatiev
Courses Plus Student 6,236 Pointscombiner
Why It is woks in local shell but not in treehouse?
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
Courses Plus Student 5,328 PointsYikes 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
Courses Plus Student 5,328 PointsHi 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
1,097 PointsI 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'
nicole lumpkin
Courses Plus Student 5,328 Pointsnicole lumpkin
Courses Plus Student 5,328 PointsPs. Nice use of the union set operator and list comprehensions :)
Ankoor Bhagat
1,097 PointsAnkoor Bhagat
1,097 PointsHi Nicole, I usually work on Jupyter notebook, I pasted the wrong code here. In Jupyter notebook I had fixed
.
andi
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.