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

Hi, Whats wrong with this code? when i run it the outcome is [(3, 'c')] instead of [(1 'a'), (2, 'b'), (3, 'c')]

def combo(mylist, mystring): myls = [] for num, char in enumerate(mylist, mystring): combin = num,char my_tuple = tuple(combin)
myls.append(my_tuple)
return myls

1 Answer

Steven Parker
Steven Parker
231,198 Points

The "enumerate" function takes one iterable argument, but this code is passing it two of them. Perhaps you were intending to use something else? See more details on the documentation page for enumerate().

Also, it's very difficult to read unformatted code. When posting code in the forum, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

Thank very much.