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

Can you help me to make a better code?

I can't understand, how can I clear the first list (my_list) and use it to add my tuples there, instead of creating a new empty list (my_list2)? Please help if you know...

This code works, but when i delete my_list2 and clear() my_list, it returns a lot of unusual stuff..

def combo (*args):
    my_list = []
    my_list2 = []
    my_tuple = None
    count = 0
    while True:
        try:
            for num in args:
                my_list.append(num[count])
                my_tuple = tuple(my_list)
            my_list2.append(my_tuple)
            my_list.clear()
            count+=1
        except IndexError:
            break
    print(my_list2)

3 Answers

What challenge is this for?

It's last challenge in Python collectons in Tuples, named combo. Sorry, I don't know how to make tags...

I'm actually working on the same challenge right now and am stumped... if I get a solution I will bring it here.

Ookey, thanks :)

https://teamtreehouse.com/community/stuck-on-this-one-5

check out this post, it helped me pass it. The one thing I do not understand about the solution (Which works by the way...) is why he included a , at the end of the line that starts with

output +=

if you can figure that out can you let me know?

Yes, a lot of information there, thanks, but i have already passed it, I just wanted to simplify my code.