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 (Retired) Tuples Combo

Not sure why my func is not passing bc it works when I test it in Workspace & my output is as noted # [(1, 'a'), (2..

combo([1, 2, 3, 4, 5, 6, 7, 8, 9], 'Treehouse')                                                                
# comes out as
# [(1, 'T'), (2, 'r'), (3, 'e'), (4, 'e'), (5, 'h'), (6, 'o'), (7, 'u'), (8, 's'), (9, 'e')] 
# not sure what I'm doing wrong in the code that makes in not passable in the challenge, thx.
def combo(iter1, iter2):
  iter1_dict = {}  
  iter2_dict = {}
  combo_dict = {}
  combo_list = []
  for item in enumerate(iter1): 
    iter1_dict.update({item[0]: item[1]}) 
  for item in enumerate(iter2): 
    iter2_dict.update({item[0]: item[1]}) 
  for key in iter1_dict:
    combo_dict.update({iter1[key]: iter2[key]})
  for key, value in combo_dict.items():
    combo_list.append((key, value))
  print(combo_list)
  return combo_list

1 Answer

Hi lynnmorgan,

This won't pass the challenge because you're pulling from a dictionary, which is unordered, to make your list, which is supposed to be ordered.

There are several ways to complete this challenge, but an easy way that uses your skills learned so far is;

def combo(iter1, iter2):
  result = []
  for index, value in enumerate(iter1):
    tuple = value, iter2[index]
    result.append(tuple)
  return result

The easiest way is;

def combo(iter1, iter2):
  return list(zip(iter1, iter2))

Thanks Evan! Much simpler and a good lesson for me to remember that dictionaries are unordered.