CSE 1010 Lecture 14: CSE 1010 - Lecture 14 - Dictionaries

60 views2 pages
Verified Note

Document Summary

Cse 1010 - introduction to computing for engineers. Instead of having indexes like a list does, a dictionary is a container of key-value pairs. Similar to a list (but is not a list) Uses variables to store and manipulate data. Example: supp = {(cid:359)cutter(cid:360): (cid:616), (cid:359)pencil(cid:360): (cid:616), (cid:359)ruler(cid:360): (cid:616), (cid:359)scissors(cid:360): (cid:617), (cid:359)paper_clip(cid:360):(cid:617), (cid:359)push_pin(cid:360):(cid:619)} The cutter" and pencil" are what"s called keys. Example of a dictionary that converts a number"s name to its value: conv_dig = {(cid:359)one(cid:360):(cid:616), (cid:359)two(cid:360):(cid:617), (cid:359)three(cid:360):(cid:618), (cid:359)four(cid:360):(cid:619), (cid:359)five(cid:360):(cid:620)} The method get() returns a value for the given key. If the key is not available, then it will return the default value. This is how you"d implement it: dict. get(key, default=none) Using get() with the con_dig from above: You can add an item to the end of a list by using append, but in a dictionary, this is what you do: How to delete an item from a dictionary: del variable[(cid:359)associated value/pair"]

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents