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

Cannot get any closer to answer - any help really appreciated!

Have spent about 4 hours on trying to get this to work over 2 days now and have tried it all the ways I can think of (and still not working). I am trying to .append the tuples to a list by using enumerate on an iterable but within that for loop putting another to set (in this case) the useless index equal to values in the second iterable. The output is a list of tuples, where the enumerated iterable in the first for loop is reading sequentially but the second iterable is reading the same value. Run it to see - very strange. Can anyone tell me why the script is not running? Kenneth Love

Output = [(3, 'a'), (3, 'b'), (3, 'c')]

zippy.py
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
# If you use .append(), you'll want to pass it a tuple of new values.
iterable_1 = [1, 2, 3]
iterable_2 = 'abc'
num_list = []

def combo(iterable_1, iterable_2):
    for index, value in enumerate(iterable_2):
        for num in iterable_1:
            index = num
        num_list.append((index, value))
    return(num_list)

2 Answers

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

You dont have to assign values to parameters as they are part of the function. Heres a simpler solution:

def combo(iter1, iter2):
  combo_list = []
  for index, value in enumerate(iter1):
    tuple = value, iter2[index]
    combo_list.append(tuple)
  return combo_list
Hara Gopal K
PLUS
Hara Gopal K
Courses Plus Student 10,027 Points

it was a frustrating....couldn't help but copy shamelessly