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

Combo Tuple Challenge

I've been working at the combo challenge for quite a while and I feel like I'm close, but I still don't quite have it. I get the error message "Got [(1, 'T'), (2, 'r')], expected [(1, 'T'), (2, 'r'), (3, 'e'), (4, 'e'), (5, 'h'), (6, 'o'), (7, 'u'), (8, 's'), (9, 'e')]".

Here is the link to the challenge

def combo(iterable1, iterable2):
  combo_list = []
  a = []
  b = []
  index = 0
  for item in iterable1:
    a.append(item)
  for item in iterable2:
    b.append(item)
  for item in a, b:
    c = a[index], b[index]
    combo_list.append(c)
    del c
    index += 1
  return combo_list

4 Answers

Hello friend, let me show you what I did, it was with 1 variable and 1 loop. Hope this helps :)

def combo(iterable1,iterable2):
  tuple_list= []
  for idx in range(len(iterable1)):
    tuple_list.append((iterable1[idx],iterable2[idx]))
  return tuple_list

Thank you so much! I knew I must have been making it too complicated.

You're welcome :) I'm glad I could help you

You da best

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

This is also a great challenge to use enumerate() on. It should save you a lookup.

There's also a handy function called zip(). Try running zip([1, 2, 3], ['a', 'b', 'c']) or look up the documentation for zip.

[MOD: fixed formatting]

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Aww, don't make it easy! :)

But, yes, zip() does exist and I did just make you build it yourself.

My solution using the enumerate method.

def combo (itr1, itr2): tuple_list = [] for index, value in enumerate (itr1): tuple_list.append((value, itr2[index])) return tuplelist