d = dict(); print d # {} - dizionario vuoto a=[('u',1), ('v',2)] d=dict(a); print d # {'u': 1, 'v': 2} --------------------------------------- cogen1=dict(Gly='ggg gga ggc ggt', Ala='gcg gca gcc gct',...) --------------------------------------- voci=['Rossi','Verdi','Bianchi'] stipendi=[1800,1500,2100] print dict(zip(voci,stipendi)) # {'Bianchi': 2100, 'Rossi': 1800, # 'Verdi': 1500} --------------------------------------- spec = dict(agrave=224, ntilde=241, zeta=950, infin=8734) --------------------------------------- inv = {} for x,y in tab.items(): inv[y]=x --------------------------------------- tab=dict(a=1, b=2) tab1=dict(b=300, c=4, d=5) tab.update(tab1) print tab # {'a': 1, 'c': 4, 'b': 300, 'd': 5} --------------------------------------- def f (**tab): print tab --------------------------------------- f(u=4,v=6,n=13) # {'n': 13, 'u': 4, 'v': 6} --------------------------------------- def menu (scelte, testo=''): while 1: risposta=raw_input(testo) if risposta=='fine': break if scelte.has_key(risposta): scelte[risposta]() def curva (): print 'Disegno una curva.' def media (): print 'Calcolo la media.' def file (): print 'Carico un file.' scelte=dict(c=curva, m=media, f=file) menu(scelte,'scelta: ') --------------------------------------- def menu (scelte, testo=''): while 1: risposta=raw_input(testo) if risposta=='fine': break scelte.get(risposta,passa)() def passa (): pass --------------------------------------- def concatl (*v): a=[] for x in v: a.extend(x) return a a=[0,1,2,3,4,5] b=[6,7,8]; c=[9,10,11,12] print concatl(a,b,c) # [0,1,2,3,4,5,6,7,8,9,10,11,12] --------------------------------------- a=7; b=a; del a; print b # 7 print a # Errore: il nome a non e' definito c=7; d=c; del d; print c # 7 print d # Errore: il nome a non e' definito --------------------------------------- a=88; b=a; c=a; del a,c print b # 88 --------------------------------------- a=[0,1,2,3,4,5,6,7] del a[1]; print a # [0, 2, 3, 4, 5, 6, 7] b=[0,1,2,3,4,5,6,7] del b[2:5]; print b # [0, 1, 5, 6, 7] --------------------------------------- def spezza (a): x=a[0]; del a[0]; return x a=[0,1,2,3,4,5,6] x=spezza(a) print x, a # 0 [1, 2, 3, 4, 5, 6] --------------------------------------- voti = {'Rossi' : 28, 'Verdi' : 27, 'Bianchi' : 25} del voti['Verdi'] print voti # {'Bianchi': 25, 'Rossi': 28} --------------------------------------- a=[0,1,2,3,4,5] a.remove(2); print a[2] # 3