-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0068_shelve.py
More file actions
63 lines (47 loc) · 1.38 KB
/
0068_shelve.py
File metadata and controls
63 lines (47 loc) · 1.38 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import shelve
# with shelve.open('ShelfTest') as fruit:
fruit = shelve.open('ShelfTest')
fruit['orange'] = "a sweet, orange, citrus fruit"
fruit['apple'] = "good for making cider"
fruit['lemon'] = "a sour, yellow citrus fruit"
fruit['grape'] = "a small, sweet fruit growing in bunches"
fruit['lime'] = "a sour, green citrus fruit"
print(fruit['grape'])
print(fruit['lemon'])
print(fruit)
fruit['lime'] = 'great with tequila'
for snack in fruit:
print(snack + ": " + fruit[snack])
print('=' * 40)
# while True:
# dict_key = input('Please enter a fruit: ')
# if dict_key == 'quit':
# break
# if dict_key in fruit:
# description = fruit[dict_key]
# print(description)
# else:
# print('We don\'t have a ' + dict_key)
# ordered_keys = list(fruit.keys())
# ordered_keys.sort()
# for f in ordered_keys:
# print(f + " - " + fruit[f])
for v in fruit.values():
print(v)
print(fruit.values())
for f in fruit.items():
print(f)
print(fruit.items())
print('=' * 40)
fruit.close()
with shelve.open('ShelfTest') as fruit:
fruit = {
"orange": "a sweet, orange, citrus fruit",
"apple": "good for making cider",
"lemon": "a sour, yellow citrus fruit",
"grape": "a small, sweet fruit growing in bunches",
"lime": "a sour, green citrus fruit"
}
print(fruit['lemon'])
print(fruit['grape'])
print(fruit)