code mastery

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/9

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

10 Terms

1
New cards

Code to count word frequencies using a dict

counts = {}
for word in words: 
	counts[word] = counts.get(word, 0) + 1

2
New cards

Dict Key-Value Loop

for key, value in my_dict.items():
    print(key, value)

3
New cards

How do you remove a key-value pair and return the value?

dict_name.pop("key")

4
New cards

How do you remove a key-value pair

del dict_name["key"]  

5
New cards

How do you find the number of key-value pairs in a dictionary?

len(dict_name)

6
New cards

How do you add a new key-value pair (e.g., "B3": "Fanta") to a dictionary?

dict_name["new_key"] = "new_value"

7
New cards

How do you change the value associated with an existing key (e.g., update "A1" to "Twix")

dict_name["existing_key"] = "new_value"  

8
New cards

Literal syntax of set

my_set = {1, 2, 3}

9
New cards

empty set

empty_set = set()

10
New cards

add single element to set

my_set.add(4)