Repository navigation
Expand file tree
/
Copy pathFourthProgram.py
More file actions
124 lines (88 loc) · 2.28 KB
/
Copy pathFourthProgram.py
File metadata and controls
124 lines (88 loc) · 2.28 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Dictionary in Python:
PersonalInfo = {
"Name" : "M.Hilal",
"Age" : 20,
"Address" : "Mardan",
"Learning" : "Python"
}
print(PersonalInfo)
print(PersonalInfo["Address"])
print(PersonalInfo["Learning"])
PersonalInfo["Name"] = "Hilal"
print(PersonalInfo)
PersonalInfo["FirstName"] = "Muhammad"
print(PersonalInfo)
# Nested Dictionary:
PersonalInfo = {
"Name" : "M.Hilal",
"Age" : 20,
"Address" : "Mardan",
"Learning" : "Python",
"Eduacation" : {
"Matric" : 922,
"FSc" : 900,
"4SemesterGpa" : 3.32
}
}
print(PersonalInfo)
print(PersonalInfo["Eduacation"])
print(PersonalInfo["Eduacation"]["FSc"])
# Dictionary Methods:
PersonalInfo = {
"Name" : "M.Hilal",
"Age" : 20,
"Address" : "Mardan",
"Learning" : "Python",
"Eduacation" : {
"Matric" : 922,
"FSc" : 900,
"4SemesterGpa" : 3.32
}
}
print(PersonalInfo.keys())
print(tuple(PersonalInfo.values()))
print(list(PersonalInfo.values()))
print(PersonalInfo.items())
print(PersonalInfo.get("Address"))
PersonalInfo.update({"FatherName" : "Zareen Taj"})
print(PersonalInfo)
# Sets in Python:
collection = {1, 2, 3, 3, 4, 4, "M", "hilal"}
print(collection)
collect = () # that is an empty Set
# Set Methods:
collect = {1, 2, 3, 3, 4, 4, "M", "hilal"}
collect1 = {1, 2, 3, 5, 6, 7, 8, 9, 10}
collect.add(5)
collect.remove("M")
collect.clear()
print(collect.pop())
print(collect)
print(collect.union(collect1))
print(collect.intersection(collect1))
# Question:
PythonDict = {
"Table" : ["a piece of furniture", "list of facts & figures "],
"cat" : "a small animal"
}
print(PythonDict)
# Question:
subjects = {"python", "java", "C++", "python", "javascript", "java", "python", "java", "C++", "C"}
print(subjects)
print(len(subjects))
# Question:
SubjectDict = {}
Input1 = int(input("Enter subject1 marks:"))
Input2 = int(input("Enter subject2 marks:"))
Input3 = int(input("Enter subject3 marks:"))
SubjectDict.update({"Math" : Input1})
SubjectDict.update({"Phy" : Input2})
SubjectDict.update({"Bio" : Input3})
print(SubjectDict)
# Question:
value = {9, "9.0"}
value = {
("float", 9),
("int", 9.0)
}
print(value)