dictionaries

0.0(0)
studied byStudied by 0 people
0.0(0)
call with kaiCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
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
Call with Kai

No study sessions yet.

10 Terms

1
New cards

dictionary

-data structure that consists of key value pairs

-known as associative arrays in some other language, are indexed by keys rather than a numerical index

-keys can be immutable type: number, strings, booleans, etc.

-values can be whatever you want

-empty dict= {}

-dict()

-retrieve values using dict[key]

2
New cards

dict.get()

the get() method will look for a given key in a dictionary. if the key exists, it will return the corresponding value. otherwise it returns None

3
New cards

pop()

method accepts a key and will delete the corresponding key-value pair in the dictionary. it returns the deleted value

4
New cards

popitem()

deletes the most recently added key-value pair. it returns the item as a tuple

5
New cards

clear()

deletes all items from a dictionary. it returns None

6
New cards

del statement

remove items from a dictionary. not a method

7
New cards

update

update method will update a dictionary using the key value pairs from a second dictionary, passed as the argument

8
New cards

** trick

we can use two stars ** to combine multiple dictionaries into a new resulting dictionary

9
New cards

dict union

python 3.9 added the diction union operator(|) it will return a new dict containing the items from the left and right dicts. in the case of duplicated keys, the right side “wins”

10
New cards