-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionary_programs.py
61 lines (59 loc) · 2.41 KB
/
dictionary_programs.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
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
# Microprogram 1
# Create a dictionary a name of grocery
grocery = {"Milk": 45, "Biscuit": 10, "Rice": 35, "Chocolate": 5, "Millet's": 25, "Oil": 78, "Ballpoint Pen": 7}
for itemName, itemPrice in grocery.items():
# Price change increase 10% for all products
grocery[itemName] = round(itemPrice * 1.2, 2)
print(grocery)
print()
# Delete the one product
# groceryList = list(grocery.keys())
for itemName in list(grocery.keys()): # list() - typecasting "change from dictionary to list"
if itemName == "Millet's":
del grocery[itemName]
print(grocery)
# Typecasting
groceryList = list(grocery.keys())
for item in groceryList:
print(item)
print()
# Microprogram 2
# I mistake enter the key is name and values is id, But id is a key and value is name. how change the key and values?
officeEmployee = {"Arun": 101, "Vijay": 102, "Krishna": 103, "Shafik": 104, "Dharma": 105, "Vignesh": 106,
"Vinith": 107, "Arun": 108, "Vino": 109}
officeEmployee2 = {}
for key, value in officeEmployee.items():
officeEmployee2[value] = key
print(officeEmployee2)
print()
# Microprogram 3
employeeSalary = {"Arun": 25000, "Vijay": 28000, "Krishna": 45000, "Shafik": 36000, "Dharma": 50000, "Vignesh": 78000,
"Vinith": 100000, "Vino": 150000}
employeeHighSalary = {}
employeeLowSalary = {}
for key, value in employeeSalary.items():
if value > 39000:
employeeHighSalary[key] = value
if value < 39000:
employeeLowSalary[key] = value
print("Experienced Pay Salary Candidates : ", employeeHighSalary)
print("Fresher Pay Salary Candidates : ", employeeLowSalary)
print()
# Microprogram 4 - Sorted()
employeeSalaryOrder = {"Arun": 85000, "Vijay": 28000, "Krishna": 15000, "Shafik": 36000, "Dharma": 50000,"Vignesh": 78000,"Vinith": 12000, "Vino": 15000}
for key in sorted(employeeSalaryOrder):
print(key, " : ", employeeSalaryOrder[key])
for value in sorted(employeeSalaryOrder.values()):
print(value)
# Microprogram 5
employeeSalaryOrder = {"Arun": 85000, "Vijay": 28000, "Krishna": 15000, "Shafik": 36000, "Dharma": 50000,"Vignesh": 78000,"Vinith": 12000, "Vino": 15000}
totalSalary = 0
for key in employeeSalaryOrder:
print(key, " : ", employeeSalaryOrder[key])
totalSalary+= employeeSalaryOrder[key]
print("Total Salary Amount is ", totalSalary)
totalSalary=0
for key in employeeSalaryOrder.values():
print(key)
totalSalary+= key
print("Total Salary Amount is ", totalSalary)