w6 Flashcards
(21 cards)
how to see if something is in a set
“in” operator
farm_animals.add(cow)
inserts cow into set
farm_animals.remove(cow)
removes cow from set
farm_animals.clear()
clear method empties set
print(pets | farm_animals)
creates a new set with both obj and arg
print(pets & farm_animals)
creates a new set containing items common to both
print(pets - farm_animals)
creates a new set containing items common to obj but not in arg
print(pets ^ farm_animals)
symmetric diff - creates a set with items in one set or the other but not in both
my_pets<=pets
is subset - are “my_pets” set in “pets” set
pets>=my_pets
is superset - does pets contain all of my pets
2 components of dictionaries
key and value pairs
3 characteristics of keys
unordered, any key can appear only once, are immutable
what does {} by itself mean
empty dictionary
how to clear dictionary
d.clear()
fruit_counts.get(‘apple’)
returns value associated with apple
fruit_counts.pop(‘apple’)
deletes key and its value
fruit_counts[‘mango’] = 42
adding the key mango with a value of 42
fruit_counts.keys()
returns a list-like object of dictionaries keys
fruit_counts.items()
returns a list-like object of dictionaries keys and values
fruit_counts.values()
returns a list-like object of dictionaries values
fruit_counts.update()
adds a set of key/value pairs or even another dictionary