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

What if we don't know the length of the dictionary? Can we still use unpacking to do it?

In this dictionary unpacking example, we know that there are three keys in the 'teacher' dictionary. If we provide a dictionary with 4 keys and call the print_teacher function, python will throw a TypeError.

Is there a way for us to still use unpacking to print the values? What if we don't know the length of the dictionary?

1 Answer

Yes, there is a way of doing it, by first applying the args/kwargs-needed to look up which one actually was since it was a while since I learnt about unpacking on Treehouse, however , you may be able to expand on the idea here https://www.geeksforgeeks.org/packing-and-unpacking-arguments-in-python/