Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introducing Dictionaries Introducing Dictionaries Creating a Dictionary

Caleb Newell
Caleb Newell
12,240 Points

Introducing Dictionaries

So this is what they said:

Challenge Task 1 of 2 Create a dictionary with the following key value pairs: 1) key: 'name', value: '', 2) key: 'topic', value: 'python'. Assign this dictionary to a variable called student.

I just don't understand what they want me to do. (a little confusing)

2 Answers

Owen Bell
Owen Bell
8,059 Points

Define a variable student, assigning to it a dictionary with two key-value pairs, those being:

'name': '',  # An empty string, '' OR ""

And

'topic': 'python',
Caleb Newell
Caleb Newell
12,240 Points

thanks for the help guys!

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,989 Points

It can be confusing at first. There are actually several ways to specify a new dict object.

A very common way is using the form b = {'one': 1, 'two': 2, 'three': 3}

In the challenge:

  • "b" would be replaced by "student"
  • 'one': 1 would be replaced by the key / value pair: 'name': ''
  • 'two': 2 would be replaced by the key / value pair: 'topic': 'python'
  • note that the first value is two single quote marks.

Post back if you need more help. Good luck!