1/9
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Code to count word frequencies using a dict
counts = {}
for word in words:
counts[word] = counts.get(word, 0) + 1Dict Key-Value Loop
for key, value in my_dict.items():
print(key, value)How do you remove a key-value pair and return the value?
dict_name.pop("key")How do you remove a key-value pair
del dict_name["key"] How do you find the number of key-value pairs in a dictionary?
len(dict_name)How do you add a new key-value pair (e.g., "B3": "Fanta") to a dictionary?
dict_name["new_key"] = "new_value"How do you change the value associated with an existing key (e.g., update "A1" to "Twix")
dict_name["existing_key"] = "new_value" Literal syntax of set
my_set = {1, 2, 3}empty set
empty_set = set()add single element to set
my_set.add(4)