Use [ , ]
-
Mutable
-
Can use indexing, slice, calculate length
-
Via assignment
.append() = add item to end
.remove() = remove first instance of a given value
.pop() = remove element of given index value
Via methods
Modify the internals of lists
-
Lists:
mydict = {"a": 1, "b": 2}
-
dictionary[key] = value to add items to a dictionary
-
mydict[key] to access item
-
x = dictionary.pop(key) to delete items from a dictionary
-
key in mydict to test for key membership
-
mydict.clear() to delete the entire contents
-
del mydict[key] to delete an entry without a return value
-
mydict.keys() to see keys
-
mydict.values() to see values
-
mydict.items() to see (key,val)
-
Dictionaries:
sets are like dictionaries without keys
-
a
-
b = set difference
-
a | b = set union
-
a & b = set intersection
-
mutable with .add() and .remove()
-
.intersection()
-
.intersection_update()
-
.difference()
-
.difference_update()
-
Sets:
keys in dictionaries and elements in sets must be "hashable"
-
int
float
str
tuple
bool
immutable built
-
in objects are hashable
-
list, dict, set cannot be keys or elements
-
Hashable:
Week 4
Saturday, 24 March 2018 5:53 PM
Foundations of Computing Page 1
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.

Already have an account? Log in

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