-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictrev02.py
37 lines (26 loc) · 1.13 KB
/
dictrev02.py
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
#!/usr/bin/python3
"""Reviewing how to work with dictionaries | Alta3 Research"""
def main():
firewalldict = {'sip':'5060', 'ssh':'22', 'http':'80'}
## display the current state of our dictionary
print(firewalldict)
## add another entry to the dict
## notice that https maps to an INT, not a STRING
firewalldict['https'] = 443
## display the dict with the new entry for host4
print(firewalldict)
## display some dictionary data
print('The print statement can be passed multiple items, provided they are separated by commas')
print("The port in use for HTTP Secure is:", firewalldict['https'])
## this SHOULD fail but it will not because we are using the .get method
print("A safer way to recall that data is to use the .get method:", \
firewalldict.get('razzledazzlerootbeer'))
## use the .keys method to return a list of keys
print(firewalldict.keys())
## use the .values method to return a list of values
print(firewalldict.values())
## remove a single key from the dict
del firewalldict["sip"]
print(firewalldict)
if __name__ == "__main__":
main()