dictionaries Flashcards
insert an input (create calculator)
input (“message”)
create dictionari called dic
dic={‘key’ : value, ‘key2’ : value2}
access a value in dictionary in key a
dic=[‘a’]
print a dictionary called dic
print (dic)
add a value xxx to dic (to a non existing key)
dic [‘newkey’]= xxx
update a value to xxx
dic [‘existingkey’]= xxx
delete a value in key a
del dic[‘a’]
check in a key ‘a’ is there (boolean)
‘a’ in dic
get list of keys
dic.keys()
get values list
dic.values()
iterate by key (i want to know the keys list)
for k in dic.keys() :
print (k)
iterate by key ( i want a list of all the values associati ad ogni possibile key, ma vedo solo i values)
for k in dic.keys() :
print (dic[k])
merge two dictionaries dic1 e dic2 (4 modi, 2 modificando uno dei dic, due senza modificarli)
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 }
definire funzione xxx con arguments gia settati (Esempio: somma)
def xxxfunction(a,b) : c=a + b return c
definire funzione xxx con arbitarry arguments
def xxxfunctionExt ( *nums) :