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) Dictionaries Packing and Unpacking Dictionaries

Sagar Thakkar
Sagar Thakkar
8,814 Points

hay can any one help me to understand packing and unpacking more please...

i am still confused about concept please help trying from 2 days

Hi Sagar, Being on the same boat and in the same city, would like to catch up. Can I have your contact detail?

Sagar Thakkar
Sagar Thakkar
8,814 Points

ya sure its https://www.facebook.com/thakkarsagar12 its not safe to put full contact detail hear meet me there

3 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Let's start with you telling me what you understand about packing/unpacking.

Sagar Thakkar
Sagar Thakkar
8,814 Points

packing is like compressing multiple values in single variable without any distortion in values, and unpacking is getting out individual variables from dict or list or single compressed variable

it is really honer to learn from you kenneth. You are one of my favourite teachers.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

OK, that's a pretty good start.

packing is like compressing multiple values in single variable

Yep, when we pack values that's exactly what we're doing.

When we unpack values, we take them from an iterable and turn them into either new variables or key/value pairs.

a, b, c = (1, 2, 3)

This unpacks the (1, 2, 3) tuple into the variables a, b, and c.

**{"name": "Kenneth", "language": "Python"}

This would unpack the dictionary into the key/value pair name="Kenneth", language="Python", like we would use as the arguments to a function.