-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapitolo14.py
More file actions
26 lines (24 loc) · 808 Bytes
/
Copy pathcapitolo14.py
File metadata and controls
26 lines (24 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from tuple import anagram_set
import shelve
def arch_anagrammi(stringa):
""" La funzione chiama la funzione anagram_set e
archivia la lista di anagrammi ottenuta in uno shelf
"""
anagrammi = anagram_set(stringa)
try:
db = shelve.open('anagrammi', 'c')
except IOError:
print('Errore apertura file: \'anagrammi\' non può essere aperto in scrittura')
else:
db[stringa] = anagrammi
db.close()
def leggi_anagrammi(stringa):
""" La funzione cerca la stringa nel database 'anagrammi'
e, se presente, restituisce la lista dei suoi anagrammi
"""
try:
db = shelve.open('anagrammi', 'r')
except IOError:
print('Errore apertura file: \'anagrammi\' non può essere aperto in lettura')
else:
return db[stringa]