- [Instructor] Now let's take a look…at how to use comprehensions…when working with dictionaries.…So I'll open dictcomp_start in my editor…in my Comprehensions folder,…and in this example,…I'll again use a list of temperatures,…this time just the Celsius ones.…So let's suppose I wanted to build a dictionary…that mapped each Celsius temperature value…with its corresponding value in the Fahrenheit scale?…Now, to do that,…I would need to build a dictionary…where Celsius temperature will be the key…and the value will be the Fahrenheit temperature…for that Celsius key.…
So let's start by defining a new variable called tempDict,…and what I need to do in this case…is create both a key and a value…from each temperature in the Celsius list.…And remember we want to be able…to look up each Fahrenheit value given the Celsius value,…so that means each Celsius value needs to be the key.…So inside the expression here,…I'll write t colon,…and that's going to be t times nine fifths plus 32.…
So that's the expression.…And then once again I'll write for t in ctemps.…
- Truth value testing
- Template strings
- Advanced Python functions
- Advanced collections
- Advanced classes and objects
- Python comprehensions: list, dictionary, and set
Skill Level Advanced
1. Python Language Features
2. Built-In Functions
3. Advanced Python Functions
4. Advanced Collections
5. Advanced Classes and Objects
6. Using Logging
7. Python Comprehensions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.