Python 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
Type "copyright", "credits" or "license" for more information.
IPython 7.8.0 -- An enhanced Interactive Python.
In [1]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/lezione8.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni')
In [2]: genera_indice(agenda, 'tel')
Out[2]:
{'555113113': [0],
'555117171': [1],
'56251451': [2],
'243124215': [3],
'573753477': [4],
'143541265': [5]}
In [3]: genera_indice(agenda, 'nome')
Out[3]:
{'Paperino': [0],
'Minnie': [1],
'Topolino': [2],
'Paperoga': [3],
'Gastone': [4],
'Paperon de Paperoni': [5]}
In [4]: indice_nome = genera_indice(agenda, 'nome')
In [5]: indice_tel = genera_indice(agenda, 'tel')
In [6]: indice_indirizzo = genera_indice(agenda, 'indirizzo')
In [7]: agenda[indice_nome['Topolino']]
Traceback (most recent call last):
File "<ipython-input-7-bd18aec70373>", line 1, in <module>
agenda[indice_nome['Topolino']]
TypeError: list indices must be integers or slices, not list
In [8]:
In [8]: agenda[indice_nome['Topolino']][0]
Traceback (most recent call last):
File "<ipython-input-8-805c872c6bad>", line 1, in <module>
agenda[indice_nome['Topolino']][0]
TypeError: list indices must be integers or slices, not list
In [9]:
In [9]: agenda[indice_nome['Topolino'][0]]
Out[9]: {'nome': 'Topolino', 'tel': '56251451', 'indirizzo': 'Via del melo 110'}
In [10]: agenda[indice_nome['Topolino'][0]]['indirizzo']
Out[10]: 'Via del melo 110'
In [11]: agenda[indice_nome['Topolino'][0]]['tel']
Out[11]: '56251451'
In [12]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/lezione8.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni')
In [13]: indice_indirizzo = genera_indice(agenda, 'indirizzo')
In [14]: indice_tel = genera_indice(agenda, 'tel')
In [15]: indice_nome = genera_indice(agenda, 'nome')
In [16]: for pos in indice_tel['555113113']:
...: print( agenda[pos]['nome'])
...:
Paperino
Qui
Quo
Qua
In [17]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/lezione8.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni')
In [18]: genera_indice_unico(agenda, 'tel')
Out[18]:
{'555113113': 8,
'555117171': 1,
'56251451': 2,
'243124215': 3,
'573753477': 4,
'143541265': 5}
In [19]: agenda[8]
Out[19]: {'nome': 'Qua', 'tel': '555113113', 'indirizzo': 'Via del pero 113'}
In [20]: { x**2 for x in range(10) }
Out[20]: {0, 1, 4, 9, 16, 25, 36, 49, 64, 81}
In [21]: type( { x**2 for x in range(10) } )
Out[21]: set
In [22]: { x**2 for x in range(0) }
Out[22]: set()
In [23]: [ [ x*y for x in range(1,11) ] for y in range(1, 11) ]
Out[23]:
[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30],
[4, 8, 12, 16, 20, 24, 28, 32, 36, 40],
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50],
[6, 12, 18, 24, 30, 36, 42, 48, 54, 60],
[7, 14, 21, 28, 35, 42, 49, 56, 63, 70],
[8, 16, 24, 32, 40, 48, 56, 64, 72, 80],
[9, 18, 27, 36, 45, 54, 63, 72, 81, 90],
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]]
In [24]: [ x*y for x in range(1,11) for y in range(1, 11) ]
Out[24]:
[1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
2,
4,
6,
8,
10,
12,
14,
16,
18,
20,
3,
6,
9,
12,
15,
18,
21,
24,
27,
30,
4,
8,
12,
16,
20,
24,
28,
32,
36,
40,
5,
10,
15,
20,
25,
30,
35,
40,
45,
50,
6,
12,
18,
24,
30,
36,
42,
48,
54,
60,
7,
14,
21,
28,
35,
42,
49,
56,
63,
70,
8,
16,
24,
32,
40,
48,
56,
64,
72,
80,
9,
18,
27,
36,
45,
54,
63,
72,
81,
90,
10,
20,
30,
40,
50,
60,
70,
80,
90,
100]
In [25]: %pprint
Pretty printing has been turned OFF
In [26]: [ x*y for x in range(1,11) for y in range(1, 11) ]
Out[26]: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
In [27]: [ x*y for x in range(1,11) if x%2 for y in range(1, 11) ]
Out[27]: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90]
In [28]: [ x*y for x in range(1,11) if x%2 for y in range(1, 11) if x==y ]
Out[28]: [1, 9, 25, 49, 81]
In [29]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/lezione8.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni')
In [30]: lista1
Traceback (most recent call last):
File "<ipython-input-30-28c806bba2a7>", line 1, in <module>
lista1
NameError: name 'lista1' is not defined
In [31]:
In [31]: lista
Out[31]: [1, 9, 25, 49, 81]
In [32]: lista2
Out[32]: [1, 9, 25, 49, 81]
In [33]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/lezione8.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni')
In [34]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27')
test_1 (__main__.Test) ... FAIL
test_2 (__main__.Test) ... FAIL
======================================================================
FAIL: test_1 (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/anaconda3/envs/F19/lib/python3.7/site-packages/ddt.py", line 145, in wrapper
return func(self, *args, **kwargs)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 38, in test
return self.do_test(tabella, colonna, valore, expected, expectedTab)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 28, in do_test
tabella, expectedTab, f"Il risultato deve essere {expectedTab} invece che {tabella}")
AssertionError: Lists differ: [{'C1': 4, 'C3': 'a'}, {'C1': 8, 'C3': 'c'}] != [{'C1': 2, 'C3': 'd'}, {'C1': 6, 'C3': 'b'}]
First differing element 0:
{'C1': 4, 'C3': 'a'}
{'C1': 2, 'C3': 'd'}
- [{'C1': 4, 'C3': 'a'}, {'C1': 8, 'C3': 'c'}]
? ^ ^ ^ ^
+ [{'C1': 2, 'C3': 'd'}, {'C1': 6, 'C3': 'b'}]
? ^ ^ ^ ^
: Il risultato deve essere [{'C1': 2, 'C3': 'd'}, {'C1': 6, 'C3': 'b'}] invece che [{'C1': 4, 'C3': 'a'}, {'C1': 8, 'C3': 'c'}]
======================================================================
FAIL: test_2 (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/anaconda3/envs/F19/lib/python3.7/site-packages/ddt.py", line 145, in wrapper
return func(self, *args, **kwargs)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 38, in test
return self.do_test(tabella, colonna, valore, expected, expectedTab)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 26, in do_test
result, expected, f"Il risultato deve essere {expected} invece che {result}")
AssertionError: 0 != 4 : Il risultato deve essere 4 invece che 0
----------------------------------------------------------------------
Ran 2 tests in 0.004s
FAILED (failures=2)
0 test passed, 2 tests failed
In [35]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27')
Reloaded modules: testlib, program
test_1 (__main__.Test) ... FAIL
test_2 (__main__.Test) ... FAIL
======================================================================
FAIL: test_1 (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/anaconda3/envs/F19/lib/python3.7/site-packages/ddt.py", line 145, in wrapper
return func(self, *args, **kwargs)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 38, in test
return self.do_test(tabella, colonna, valore, expected, expectedTab)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 28, in do_test
tabella, expectedTab, f"Il risultato deve essere {expectedTab} invece che {tabella}")
AssertionError: Lists differ: [{'C1': 4, 'C3': 'a'}, {'C1': 8, 'C3': 'c'}] != [{'C1': 2, 'C3': 'd'}, {'C1': 6, 'C3': 'b'}]
First differing element 0:
{'C1': 4, 'C3': 'a'}
{'C1': 2, 'C3': 'd'}
- [{'C1': 4, 'C3': 'a'}, {'C1': 8, 'C3': 'c'}]
? ^ ^ ^ ^
+ [{'C1': 2, 'C3': 'd'}, {'C1': 6, 'C3': 'b'}]
? ^ ^ ^ ^
: Il risultato deve essere [{'C1': 2, 'C3': 'd'}, {'C1': 6, 'C3': 'b'}] invece che [{'C1': 4, 'C3': 'a'}, {'C1': 8, 'C3': 'c'}]
======================================================================
FAIL: test_2 (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/anaconda3/envs/F19/lib/python3.7/site-packages/ddt.py", line 145, in wrapper
return func(self, *args, **kwargs)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 38, in test
return self.do_test(tabella, colonna, valore, expected, expectedTab)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 26, in do_test
result, expected, f"Il risultato deve essere {expected} invece che {result}")
AssertionError: 0 != 4 : Il risultato deve essere 4 invece che 0
----------------------------------------------------------------------
Ran 2 tests in 0.004s
FAILED (failures=2)
0 test passed, 2 tests failed
In [36]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27')
Reloaded modules: testlib, program
test_1 (__main__.Test) ... ok
test_2 (__main__.Test) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.001s
OK
2 test passed, 0 tests failed
In [37]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27')
Reloaded modules: testlib, program
test_1 (__main__.Test) ... ERROR
test_2 (__main__.Test) ... ERROR
======================================================================
ERROR: test_1 (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/anaconda3/envs/F19/lib/python3.7/site-packages/ddt.py", line 145, in wrapper
return func(self, *args, **kwargs)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 38, in test
return self.do_test(tabella, colonna, valore, expected, expectedTab)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 24, in do_test
result = program.es27(tabella, colonna, valore)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/program.py", line 83, in es27
if riga[nome] != valore:
NameError: name 'nome' is not defined
======================================================================
ERROR: test_2 (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/anaconda3/envs/F19/lib/python3.7/site-packages/ddt.py", line 145, in wrapper
return func(self, *args, **kwargs)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 38, in test
return self.do_test(tabella, colonna, valore, expected, expectedTab)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py", line 24, in do_test
result = program.es27(tabella, colonna, valore)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/program.py", line 83, in es27
if riga[nome] != valore:
NameError: name 'nome' is not defined
----------------------------------------------------------------------
Ran 2 tests in 0.003s
FAILED (errors=2)
2 test passed, 0 tests failed
In [38]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27/test.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/27')
Reloaded modules: testlib, program
test_1 (__main__.Test) ... ok
test_2 (__main__.Test) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.002s
OK
2 test passed, 0 tests failed
In [39]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/11/test.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/11')
Reloaded modules: testlib, program
test_1 (__main__.Test) ... FAIL
test_2 (__main__.Test) ... ok
test_3 (__main__.Test) ... ok
======================================================================
FAIL: test_1 (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/anaconda3/envs/F19/lib/python3.7/site-packages/ddt.py", line 145, in wrapper
return func(self, *args, **kwargs)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/11/test.py", line 35, in test
return self.do_test(testo, expected)
File "/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/11/test.py", line 26, in do_test
self.assertEqual(result, expected, f"Il risultato deve essere {expected} invece che {result}")
AssertionError: {'prt[128 chars], 'rt': ['otre', 'tre'], 'lp': ['piolo', 'polo'], '': ['', '']} != {'prt[128 chars], 'rt': ['otre', 'tre'], 'lp': ['piolo', 'polo']}
- {'': ['', ''],
- 'cs': ['casa', 'cosa'],
? ^
+ {'cs': ['casa', 'cosa'],
? ^
'fll': ['follia', 'fallo', 'folla'],
'lp': ['piolo', 'polo'],
'pr': ['arpia', 'arpa'],
'prt': ['parto', 'porta'],
'r': ['era', 'ora'],
'rt': ['otre', 'tre']} : Il risultato deve essere {'prt': ['parto', 'porta'], 'r': ['era', 'ora'], 'pr': ['arpia', 'arpa'], 'cs': ['casa', 'cosa'], 'fll': ['follia', 'fallo', 'folla'], 'rt': ['otre', 'tre'], 'lp': ['piolo', 'polo']} invece che {'prt': ['parto', 'porta'], 'r': ['era', 'ora'], 'pr': ['arpia', 'arpa'], 'cs': ['casa', 'cosa'], 'fll': ['follia', 'fallo', 'folla'], 'rt': ['otre', 'tre'], 'lp': ['piolo', 'polo'], '': ['', '']}
----------------------------------------------------------------------
Ran 3 tests in 0.004s
FAILED (failures=1)
2 test passed, 1 tests failed
In [40]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/11/test.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/11')
Reloaded modules: testlib, program
test_1 (__main__.Test) ... ok
test_2 (__main__.Test) ... ok
test_3 (__main__.Test) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.004s
OK
3 test passed, 0 tests failed
In [41]: