1: l=[1,2,3] 2: l.index(2) 1 3: l.index(1) 0 4: l.index(5) 5: d={1:54,765:3} 6: 766 in d False 7: runfile('C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018/conta_elem.py', wdir='C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018') 8: runfile('C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018/conta_elem.py', wdir='C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018') 9: runfile('C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018/conta_elem.py', wdir='C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018') 10: ripetizione_elementi([1,2,2,2,"b","a","a",2.0,2.0,2.0,"casa","casa",2.0]) [(1, 1), (2, 7), ('b', 1), ('a', 2), ('casa', 2)] 11: runfile('C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018/conta_elem.py', wdir='C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018') 12: runfile('C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018/conta_elem.py', wdir='C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018') 13: ripetizione_elementi([1,2,2,2,"b","a","a",2.0,2.0,2.0,"casa","casa",2.0]) [((1, int), 1), ((2, int), 3), (('b', str), 1), (('a', str), 2), ((2.0, float), 4), (('casa', str), 2)] 14: runfile('C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018/conta_elem.py', wdir='C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018') 15: ripetizione_elementi([1,2,2,2,"b","a","a",2.0,2.0,2.0,"casa","casa",2.0]) [(1, 1), (2, 3), ('b', 1), ('a', 2), (2.0, 4), ('casa', 2)] 16: ripetizione_elementi([1,2,2,2,"b","a","a",2.0,2.0,2.0,"casa","casa",2.0,"2","2"]) [(1, 1), (2, 3), ('b', 1), ('a', 2), (2.0, 4), ('casa', 2), ('2', 2)] 17: runfile('C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018/conta_elem.py', wdir='C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018') 18: d={"salve":1, "ciao":3,"hello":4} 19: d["salve"] 1 20: d.get("salve") 1 21: d["salv"] 22: d.get("salv") 23: d.get("salv",-1) -1 24: from collections import defaultdict 25: d=defaultdict(0) 26: d=defaultdict(lambda : 0) 27: d["asd"] 0 28: import random 29: l=[random.randint(0,10000) for i in range (100000)] 30: len(l) 100000 31: l[4:10] [6633, 9603, 9484, 4246, 5149, 9624] 32: %timeit l.count(5000) 33: %timeit l[5000] 34: %timeit l.remove(5000) 35: %timeit l.pop(5000) 36: runfile('C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018/conta_elem.py', wdir='C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018') 37: ripetizione_elementi([1,2,2,2,"b","a","a",2.0,2.0,2.0,"casa","casa",2.0,"2","2"]) [(1, 1), (2, 3), ('b', 1), ('a', 2), (2.0, 4), ('casa', 2), ('2', 2)] 38: ripetizione_elementi_count([1,2,2,2,"b","a","a",2.0,2.0,2.0,"casa","casa",2.0,"2","2"]) [(1, 1), (2, 7), ('b', 1), ('a', 2), ('casa', 2), ('2', 2)] 39: runfile('C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018/conta_elem.py', wdir='C:/Users/Angelo/OneDrive - uniroma1.it/pythonFDP2018') 40: ripetizione_elementi_count([1,2,2,2,"b","a","a",2.0,2.0,2.0,"casa","casa",2.0,"2","2"]) [((1, int), 1), ((2, int), 7), (('b', str), 1), (('a', str), 2), ((2.0, float), 7), (('casa', str), 2), (('2', str), 2)] 41: l=[random.randint(0,10000) for i in range (100000)] 42: %timeit ripetizione_elementi(l) 43: %timeit ripetizione_elementi_cout(l) 44: %timeit ripetizione_elementi_count(l) 45: %timeit ripetizione_elementi(l) 46: %timeit ripetizione_elementi(l) 47: %timeit ripetizione_elementi(l) 48: %timeit ripetizione_elementi(l) 49: d defaultdict(>, {'asd': 0}) 50: print(d) 51: d={"salve":1, "ciao":3,"hello":4} 52: sorted(d.keys()) ['ciao', 'hello', 'salve'] 53: sorted(d.values()) [1, 3, 4] 54: sorted(d.keys(), key = lambda k: d[k]) ['salve', 'ciao', 'hello'] 55: sorted(d.keys(), key = lambda k: d[k], reverse=True) ['hello', 'ciao', 'salve'] 56: d={"salve":1, "ciao":3,"hello":4, "arigatò":2} 57: sorted(d.keys(), key = lambda k: d[k]) ['salve', 'arigatò', 'ciao', 'hello'] 58: sorted(d.keys(), key = lambda k: d[k], reverse=True) ['hello', 'ciao', 'arigatò', 'salve'] 59: d.keys 60: d.keys() dict_keys(['salve', 'ciao', 'hello', 'arigatò']) 61: l=[random.randint for i in range (100000)] 62: l[4:78] [>, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >, >] 63: lambda x: x+5 > 64: sorted(d.keys(), key = lambda k: k.upper()) ['arigatò', 'ciao', 'hello', 'salve'] 65: sorted(d.keys(), key = lambda k: -d[k]) ['hello', 'ciao', 'arigatò', 'salve'] 66: d {'arigatò': 2, 'ciao': 3, 'hello': 4, 'salve': 1} 67: sorted(d.keys(), key = lambda k: d[k]) ['salve', 'arigatò', 'ciao', 'hello'] 68: l[0:3] [>, >, >] 69: l=[random.randint(0,10000) for i in range (100000)] 70: l[0:3] [192, 4773, 7245] 71: p=[i**0.5 for i in l] 72: p[0:3] [13.856406460551018, 69.0869017976635, 85.11756575466664] 73: q=map(lambda x: x**0.5, l) 74: q[0:3] 75: q=list(map(lambda x: x**0.5, l)) 76: q[0:3] [13.856406460551018, 69.0869017976635, 85.11756575466664] 77: p[0:3] [13.856406460551018, 69.0869017976635, 85.11756575466664] 78: %timeit list(map(lambda x: x**0.5, l)) 79: %timeit [i**0.5 for i in l] 80: pwd 'C:\\Users\\Angelo\\OneDrive - uniroma1.it\\pythonFDP2018' 81: ls 82: f=open("provaprint.py") 83: f <_io.TextIOWrapper name='provaprint.py' mode='r' encoding='cp1252'> 84: l=f.readlines() 85: l ['print(4,5,6,7,end="",sep="")\n', 'print(8,9,10,end="",sep="")\n'] 86: len(l) 2 87: q=f.read() 88: q '' 89: f.seek(0) 0 90: line=f.readline() 91: line 'print(4,5,6,7,end="",sep="")\n' 92: line=f.readline() 93: line 'print(8,9,10,end="",sep="")\n' 94: line=f.readline() 95: line '' 96: f.seek(0) 0 97: f.tell() 0 98: line=f.read() 99: line 'print(4,5,6,7,end="",sep="")\nprint(8,9,10,end="",sep="")\n' 100: f.close() 101: with open("provaprint.py") as f: sseq=f.readlines() 102: f <_io.TextIOWrapper name='provaprint.py' mode='r' encoding='cp1252'> 103: f.read() 104: with open("scrittura.txt","w") as f: f.write("hello") 105: with open("scrittura.txt","w") as f: print("hello", file=f) 106: with open("scrittura.txt","w") as f: for i in range(100): print(random.randint(0,1000), file = f) 107: with open("scrittura.txt","w") as f: for i in range(100): print(random.randint(0,1000), file = f) 108: with open("scrittura.txt","w") as f: for i in range(100): print("{:4}".format(random.randint(0,1000)), file = f) 109: with open("scrittura.txt","w") as f: for i in range(100): print("{:.4}".format(random.randint(0,1000)), file = f) 110: with open("scrittura.txt","w") as f: for i in range(100): print("{:4.}".format(random.randint(0,1000)), file = f) 111: with open("scrittura.txt","w") as f: for i in range(100): print("{.:4}".format(random.randint(0,1000)), file = f) 112: with open("scrittura.txt","w") as f: for i in range(100): print("{:-4}".format(random.randint(0,1000)), file = f) 113: with open("scrittura.txt","w") as f: for i in range(100): print("{:4-}".format(random.randint(0,1000)), file = f) 114: with open("scrittura.txt","w") as f: for i in range(100): print("{:,4}".format(random.randint(0,1000)), file = f) 115: with open("scrittura.txt","w") as f: for i in range(100): print("{:04}".format(random.randint(0,1000)), file = f) 116: %history -n -o -f lez6s.py