Dictionaries

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/18

flashcard set

Earn XP

Description and Tags

chapter 5

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

19 Terms

1
New cards

Dictionary classic

D = {key1:value1, key2:value2, key3:value3}

2
New cards

Indexing

print(D['key'])

3
New cards

print keys

print(D.keys())

4
New cards

print values

print(D.values())

5
New cards

print whole list

print(D.items())

6
New cards

Membership test for key

'keys' in D

7
New cards

Change item

D['b']= 'changed item'

8
New cards

Length of dictionary items

print(len(D))

9
New cards

Merge F with D, using D's keys to update F's keys

F.update(D)

10
New cards

Remove key 'a' and return its associated value

print(D.pop('a'))

11
New cards

add key (e) and a value to D

D['e']= value

12
New cards

change what key (e) equals

D['e'] = 'new value'

13
New cards

list of the keys of D

list(D.keys())

14
New cards

list of the values of D

L_values = list(D.values())

15
New cards
  • If key exists → return its value

  • If key doesn't exist → return default

value = D.get('d',default value)

16
New cards

Comprehension Purpose

replace short for loop

17
New cards

dictionary comprehension classic

{key: value for key in iterable}

{key: value for (key, value) in iterable}

18
New cards

set comprehension classic

{f(x) for x in iterable}

19
New cards