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 Functions, Packing, and Unpacking Packing and Unpacking Unpacking Challenge

i need help on this one guys i am a bit stuck here on this task

Challenge Task 1 of 1 Edit the variable assignment under the provided function so that the tuple returned from the function call is unpacked into 2 variables, val1, val2

unpacking.py
def unpacker(*args):
    return args

val = unpacker('Python', 'rocks!')

Currently, the function unpacker returns a tuple of the arguments provided when running it:

val = ("Python", "rocks!")

The video just before this challenge provides the syntax for assigning each list item to a variable:

val1, val2, val3 = ["a", "b", "c"]

# val1 = "a"
# val2 = "b"
# val3 = "c"
HΓ₯vard Hytten
HΓ₯vard Hytten
6,239 Points

You should atleast make an attempt of solving it before going stright to the community. A good pointer is to move the values to the return statement. It should look like this - return ('Python', ' rocks!'). From there you should look into Steven's suggestion from earlier. Happy coding mate.

perhaps he did try it out before he came here - like I'm doing. Perhaps you should help instead of hindering - happy coding mate

so here's how I did it val1, val2 = ("Python rocks").split(' ') and from there I jut printed the values - worked like a charm - good luck to you

6 Answers

def unpacker(*args): return args val1, val2 = unpacker('Python', 'rocks!') print(val1) print(val2)

Michael McGill
Michael McGill
2,085 Points
def unpacker(*args):
    return args

val1, val2 = unpacker('Python', 'rocks!')

This worked and I didn't need to put in the print function

Christopher Sullivan
Christopher Sullivan
4,230 Points

Dont know why, but came with the same solution but it didnt take my code. But if I copy/pasted your the checker works?

this was my answer thanks a lot guys you are so patient,

def unpacker(*args): return args val = unpacker('Python', 'rocks!') val1 = "Python" val2 = "rocks!"

thank you guys you helped me a lot, i was not referencing correctly to the second value rocks!, i was doing an error, i was leaving out the '!' like val2 = rocks instead of val2 = rocks!

def unpacker(*args): val1, val2 = unpacker[0] ,unpacker[1] return val1, val2 unpacker('Python', 'rocks!')

What is my mistake ?

def unpacker(*args): return args

val1, val2 = unpacker('Python', 'rocks!')