COMP 110 JUNE 2-6

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

1/20

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.

21 Terms

1
New cards

Why avoid in with large lists?

Must scan every item (slow for big lists).

2
New cards
Lists allow duplicates?
Yes.
3
New cards
Lists maintain order?
Yes, by index (0, 1, 2...).
4
New cards
Sets allow duplicates?
No, auto-removed.
5
New cards
How to add to a set?
my_set.add(item).
6
New cards
Empty set syntax?
set() (not {}).
7
New cards
Why use sets over lists?
Faster membership checks.
8
New cards
How to add/update a key-value pair?
my_dict["key"] = value.
9
New cards
What happens to duplicate keys?
Last value wins ({"a":1, "a":2} → {"a":2}).
10
New cards
Safe way to check keys?
"key" in my_dict or .get(key, default).
11
New cards
How to remove a key?
.pop(key) or del my_dict["key"].
12
New cards

Dictionary keys changeable?

No (must be strings, numbers, tuples).

13
New cards
Empty dict syntax?
{} or dict().
14
New cards
How to loop key-value pairs?
for key, value in my_dict.items():.
15
New cards
{1,2,2} becomes?
{1,2}.
16
New cards
len({"a":1, "b":2})?
2
17
New cards

What does for x in my_dict: loop over?

The keys (use my_dict[x] to get values).

18
New cards
Error for missing keys?
KeyError (use .get() to avoid).
19
New cards
pop() missing key?
Raises KeyError (add default: .pop(key, None)).
20
New cards

What does "zero-based" mean for lists?

First item is at index 0 (not 1).

21
New cards

How are lists sequential?

Items keep their order (index 012...).