dictionaries Flashcards

1
Q

insert an input (create calculator)

A

input (“message”)

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

create dictionari called dic

A

dic={‘key’ : value, ‘key2’ : value2}

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

access a value in dictionary in key a

A

dic=[‘a’]

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

print a dictionary called dic

A

print (dic)

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

add a value xxx to dic (to a non existing key)

A

dic [‘newkey’]= xxx

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

update a value to xxx

A

dic [‘existingkey’]= xxx

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

delete a value in key a

A

del dic[‘a’]

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

check in a key ‘a’ is there (boolean)

A

‘a’ in dic

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

get list of keys

A

dic.keys()

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

get values list

A

dic.values()

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

iterate by key (i want to know the keys list)

A

for k in dic.keys() :

print (k)

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

iterate by key ( i want a list of all the values associati ad ogni possibile key, ma vedo solo i values)

A

for k in dic.keys() :

print (dic[k])

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

merge two dictionaries dic1 e dic2 (4 modi, 2 modificando uno dei dic, due senza modificarli)

A
d1 = {'a':1, 'b':2}
 d2 = {'c':3, 'd':5}
for k in d2.keys():
	 d1[k]=d2[k]
print (d1)

d1.update(d2)

dic1.copy()
dic3=dic1.copy()
for k in dic2.keys():
	dic3[k]=dic2[k]
print(dic3)

dic3= {**dic1, **dic2 }

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

definire funzione xxx con arguments gia settati (Esempio: somma)

A
def xxxfunction(a,b) :
    c=a + b
    return c
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

definire funzione xxx con arbitarry arguments

A

def xxxfunctionExt ( *nums) :

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