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 trialKade Carlson
5,928 PointsNot sure why this isn't working
What should I do here?
def combiner(arg):
all_strings = []
all_ints = []
for item in arg:
if item isinstance(item, str):
all_strings.append(item)
elif item isinstance(item, int):
all_ints.append(item)
else:
None
return all_strings.extend(all_ints)
2 Answers
Steven Parker
231,261 PointsRemember the objective: "Return a single string that is a combination of all of the strings in the list and then the sum of all of the numbers." So you'll need to join all the strings, and then add up all the numbers and convert the result to a string and join/concatenate that also.
Also, take another look at the tests in the loop. What happens when the item is a float?
I'll bet you can get it now without an explicit code spoiler.
Nikita Anuchin
13,713 Pointsdef combiner(args): #we know input data will be dict of str or (int, float) types
my_str = '' #str placeholder
my_int = 0 #int, float
for i in args:
if isinstance(i, str): #if item type is str add it to my_str
my_str += i
else:
my_int += i
return my_str + str(my_int) #convert int type to str and add it to my_str