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

instances challenge

hey guys im not sure what im doing wrong here ,please help

instances.py
def combiner(str_num):
    mixed_list = ["mom", "eldrine", "kiki",8, 5, 8, 5, 2, 3]
    str_num = []
    nums = 0
    strings = []
    for item in mixed_list:
        if isinstance(item, str):
            strings.join(item)
        else:
            nums += item
             str_nums = strings.join(str,nums)
    return str_num      

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

You are very close. Here are the items to fix:

  • the for item loop should loop over the str_num argument, not the static test value mixed_list
  • use strings.append instead of strings.join. A list object has no join method
  • use "".join(strings) to get the strings into one string
  • use str(nums) to get the numbers into a string
  • You can use + to combine these in the return statement.
  • the str_nums assignment should be outside of the for loop

Post back if you need more help. Good luck!!

Thanks Chris I finally got it

here is what I did but im still getting a bummer saying didn't get expected result

def combiner(str_num): str_num = ["mom", "eldrine", "kiki",8, 5, 8, 5, 2, 3] nums = [] strings = [] for item in str_num: if isinstance(item, str): strings.append(item) elif isinstance(item,(int,float)): nums.append(item) nums = sum(nums) strings = "".join(strings)
return strings + str(nums)