Basic Dictionaries Flashcards

1
Q

Crear variable a diccionario con keys kn y valores vn

A

a = {k1: v1, k2: v2, k3: v3}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Imprimir valor vn de key kn de diccionario a

A
print(a[kn])
o
print(a.get(kn))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Imprimir diccionario con keys kn y valores vn

A

print({k1: v1, k2: v2, k3: v3})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Modificar valor vn de key kn de diccionario a

A

a[kn] = vn

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Añadir un nuevo key kn con valor vn a diccionario a

A

a[kn] = vn

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Borrar key kn de diccionario a

A

del a[kn]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Borrar diccionario a

A

del a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Borrar todas las keys de diccionario a

A

a.clear()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Obtener valor vn de key kn de diccionario a si kn existe y si no obtener una alternativa x

A

a.get(kn, x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Obtener keys de diccionario a

A

a.keys()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Obtener valores de diccionario a

A

a.values()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Obtener items de diccionario a

A

a.items()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Obtener lista de keys de diccionario a

A

list(a.keys())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Obtener lista de valores de diccionario a

A

list(a.values())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Obtener lista de items de diccionario a

A

list(a.items())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Crear tupla a de items de diccionario b

A

a = tuple(b.items())

17
Q

Crear diccionario a de una tupla b cuyos elementos son tuplas de dos elementos

A

a = dict(b)

18
Q

Crear diccionario a, copiando y reemplazando su contenido por el del diccionario b

A

a = b.copy()

19
Q

Añadir a diccionario a, contenido del diccionario b

A

a.update(b)

20
Q

Imprimir el valor vb de un key kb de un diccionario b que es el valor va de un key ka de otro diccionario a

A
print(a[ka][kb])
o
print(a[ka].get(kb))