CSE exam 3 cards (write eaxh response down)!

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

20 Terms

1
New cards

What is a set in python?

An unordered collection of unique elements. Duplicates are removed.

2
New cards

How do you create an empty set?

set()- {} creates an empty dictionary

3
New cards

Can you access a set using an index?

No. Sets are unordered and don’t support numerical indexing

4
New cards

What does A\|B do

Union: all unique elements in either set

5
New cards

What does A & B do

Intersection: elements found in both sets

6
New cards

What does A - B do?

Difference: elements in A but not B

7
New cards

What does A ^ B do?

Symmetric difference: elements in either set, but not in both

8
New cards

What happens when you convert a list into a set?

Duplicate elements are removed and order is not guaranteed

9
New cards

What is dictionary?

A collection of key value pairs. Each key must be unique

10
New cards

How do you access a dictionary value?

d[key]. For example: d[“name”]

11
New cards

What happens if you access a nonexistent key with d[key]?

Python raises a KeyError

12
New cards

What does d.get(key, 0) do?

Returns the value if they key exists; otherwise returns 0

13
New cards

How do you add or update a dictionary entry?

d[key] = value - adds a new key or updates an existing one

14
New cards

What does len(d) return?

The number of key-value pairs in the dictionary

15
New cards

What did key in d check?

Whether the key exists in the dictionary, not whether it’s a value

16
New cards

What does d.keys() return?

A view of the dictionary’s keys

17
New cards

What does d.values() return?

A view of the dictionary’s values

18
New cards

What does for key in d: iterate over?

The dictionary’s keys

19
New cards

What does d[key] = d.get(key, 0) + 1 do?

Increments the count for a key, starting at 0 if it’s missing

20
New cards

How do you loop through a dictionary’s keys and values?

for key, value in d.items():