Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Tuples Multiple Return Values

Dongyun Cho
Dongyun Cho
2,256 Points

stucked in Combo question~

def combo(a, b):
    dict = {}
    for i in a:
        for ii in b:
            dict[a] = b
            for a, b in dict.items():
                print (a,b)
combo('abc', '123')

I just kept trying the weirdest code ever and got numerous errors of course.... I have no idea to solve this ! Can somebody give me some hint for this!?

1 Answer

Stuart Wright
Stuart Wright
41,102 Points

Here are a couple of hints to get you started:

  • The challenge asks you to return (not print) a list of tuples. You haven't returned anything.
  • Dictionaries do not have any order, so you shouldn't be using them at all to help you with this challenge.
  • Try creating an empty list to start with.
  • Then loop over the inputs, appending tuples to the output list. Remember that since the inputs will be the same length, you can do something like:
for i in range(len(a)):
    my_tuple = (a[i], b[i])