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 trialMisha Morse
3,711 PointsHaaaaalp
This function runs just fine on pycharm and in workspaces so I feel like I'm expected to do something differently. Any suggestions are appreciated!
def combiner(*args):
strings = []
numbers = []
for arg in args:
if isinstance(arg, str):
strings.append(arg)
elif isinstance(arg, (int, float)):
numbers.append(arg)
numbers = sum(numbers)
numbers = str(numbers)
strings = "".join(strings)
result = strings + numbers
return result
4 Answers
Steven Parker
231,236 PointsThe instructions said that the function "takes a single argument, which will be a list". But the "splat" operator ("*") is for when a function takes several arguments that you want to convert into a list.
Misha Morse
3,711 PointsAh, I see. How do I specify a list as my argument in my function definition?
Steven Parker
231,236 PointsJust don't put the asterisk in front !
Misha Morse
3,711 PointsFirst off, thankyou so much for your help. This is what I'm trying now and it gives me TypeError: 'function' object is not subscriptable… :/
def combiner(args): strings = [] numbers = []
for item in args:
if isinstance(item, str):
strings.append(item)
elif isinstance(item, (int, float)):
numbers.append(item)
numbers = sum(numbers)
numbers = str(numbers)
strings = "".join(strings)
result = strings + numbers
return result
print(combiner["Misha", 6.9, "Rocks", 5.4, "Hard", 55])
Steven Parker
231,236 PointsFor the challenge, you only need to define the function, you won't need to call it yourself.
Leave out the "print" line at the end and you should pass.
Misha Morse
3,711 PointsIt condensed my first three line of codes into one line when I submitted it oh here. It doesnt really look like that
Steven Parker
231,236 PointsWhen posting code, use Markdown formatting to preserve the code's appearance.