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 Introducing Dictionaries Introducing Dictionaries Update and Mutate Dictionaries

[SOLVED] I can't seem to change any value of the dictionary course, without getting a syntax error.

The error is as stated below:

File "dictionaries.py", line 3                                                                                                                                                                                                                                                                                    
    print(course['teacher']='Luke')                                                                                                                                                                                                                                                                                 
         ^                                                                                                                                                                                                                                                                                                          
SyntaxError: keyword can't be an expression  

This is the code I adjusted:

course = {'teacher':'Ashley', 'title':'Introducing Dictionaries', 'level':'Immediate'}

print(course['teacher']='Luke')

2 Answers

I do apologize! I fixed an easy issue, with just printing out the variable itself, not the mutated variable.

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Luke Tate! The problem here is that you've got a reassignment happening inside the print() statement. But the print() function can't take an assignment without error. However, if you split that up just a bit, you get back the results you're expecting:

course['teacher']='Luke'
print(course['teacher'])
# prints out "Luke"

Hope this helps! :sparkles:

Thanks for your advice!!!! However, it exclusively prints out that specific key value, ignore everything else, including the dictionary it was in.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Luke Tate you can also just print out the entire course if you like :smiley:

course = {'teacher':'Ashley', 'title':'Introducing Dictionaries', 'level':'Immediate'}

course['teacher']='Luke'
print(course)
# prints out {'teacher': 'Luke', 'title': 'Introducing Dictionaries', 'level': 'Immediate'}

The problem that you originally had is that you had an assignment inside a print statement.

This would also not work for that same reason :smiley:

x = 100
print(x = 200)