-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictdata.py
More file actions
53 lines (47 loc) · 1.75 KB
/
dictdata.py
File metadata and controls
53 lines (47 loc) · 1.75 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
balance = {
"Samuel": 1500.75,
"Raj": 1200.50,
"John":200000.00,
"Emma": 2500.00,
"Olivia": 3000.25,
"Liam": 1800.00}
print(balance)
print(type(balance))
#accessing values using keys
print("Balance of Samuel is:", balance["Samuel"])
print("Balance of Raj is:", balance["Raj"])
print("Balance of John is:", balance["John"])
#accessing values using get() method
print("Balance of Samuel is:", balance.get("Samuel"))
print("Balance of Raj is:", balance.get("Raj"))
print("Balance of John is:", balance.get("John"))
#modifying values
balance["Samuel"] = 2000.00
print("After modifying, Balance of Samuel is:", balance["Samuel"])
balance["Raj"] = balance["Raj"] + 500.00
print("After modifying, Balance of Raj is:", balance["Raj"])
balance["John"] += 10000.00
print("After modifying, Balance of John is:", balance["John"])
#len() method
print("Number of customers in balance dictionary is:", len(balance))
#adding new key-value pair
balance["Alice"] = 3000.00
print("New entry in balance: ",balance)
#built-in methods
print("Dictionary keys are:", balance.keys())
print("Dictionary values are:", balance.values())
print("Dictionary items are:", balance.items())
print("Is John present in balance dictionary?", "John" in balance)
#pop method
removed_balance = balance.pop("Raj")
print("Removed balance of Raj is:", removed_balance)
print("Balance dictionary after removing Raj:", balance)
print("Pop items",balance.popitem())
del balance["Liam"]
print("Balance dictionary after deleting Alice:", balance)
contents = {"name": "David", "age": 30, "city": "New York"}
print(contents.clear())
new_balance = balance.copy()
print("Copied balance dictionary:", new_balance)
balance.update({"Emma": 3000.00, "Olivia": 3500.50})
print("Balance dictionary after update:", balance)