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 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,118 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])