1
+ {
2
+ "nbformat" : 4 ,
3
+ "nbformat_minor" : 0 ,
4
+ "metadata" : {
5
+ "colab" : {
6
+ "provenance" : [],
7
+ "authorship_tag" : " ABX9TyNs2quV80MkDa7cA9dgyYmy" ,
8
+ "include_colab_link" : true
9
+ },
10
+ "kernelspec" : {
11
+ "name" : " python3" ,
12
+ "display_name" : " Python 3"
13
+ },
14
+ "language_info" : {
15
+ "name" : " python"
16
+ }
17
+ },
18
+ "cells" : [
19
+ {
20
+ "cell_type" : " markdown" ,
21
+ "metadata" : {
22
+ "id" : " view-in-github" ,
23
+ "colab_type" : " text"
24
+ },
25
+ "source" : [
26
+ " <a href=\" https://colab.research.google.com/github/ambilisunil/python_basics/blob/main/DictionaryAndSet.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type" : " markdown" ,
31
+ "source" : [
32
+ " # A **dictionary** in Python is a collection of key-value pairs, where each key is unique, and values can be of any data type."
33
+ ],
34
+ "metadata" : {
35
+ "id" : " rsxNgETExEG2"
36
+ }
37
+ },
38
+ {
39
+ "cell_type" : " code" ,
40
+ "execution_count" : 4 ,
41
+ "metadata" : {
42
+ "colab" : {
43
+ "base_uri" : " https://localhost:8080/"
44
+ },
45
+ "id" : " pS9lv--gxAOH" ,
46
+ "outputId" : " 5786ac5e-e6d6-4f86-92b5-de6d31265f14"
47
+ },
48
+ "outputs" : [
49
+ {
50
+ "output_type" : " stream" ,
51
+ "name" : " stdout" ,
52
+ "text" : [
53
+ " <class 'dict'>\n " ,
54
+ " {1: 'ammu', 2: 'aji', 3: 'aju', 4: 'ammini'}\n "
55
+ ]
56
+ }
57
+ ],
58
+ "source" : [
59
+ " d_data={1:\" ammu\" ,2:\" aji\" ,3:\" aju\" ,4:\" ammini\" }\n " ,
60
+ " print(type(d_data))\n " ,
61
+ " print(d_data)"
62
+ ]
63
+ },
64
+ {
65
+ "cell_type" : " code" ,
66
+ "source" : [
67
+ " d_data[1]"
68
+ ],
69
+ "metadata" : {
70
+ "colab" : {
71
+ "base_uri" : " https://localhost:8080/" ,
72
+ "height" : 36
73
+ },
74
+ "id" : " BYzJpjRQxiew" ,
75
+ "outputId" : " 2f6a8feb-2916-47ef-dbe6-df3250320d62"
76
+ },
77
+ "execution_count" : 5 ,
78
+ "outputs" : [
79
+ {
80
+ "output_type" : " execute_result" ,
81
+ "data" : {
82
+ "text/plain" : [
83
+ " 'ammu'"
84
+ ],
85
+ "application/vnd.google.colaboratory.intrinsic+json" : {
86
+ "type" : " string"
87
+ }
88
+ },
89
+ "metadata" : {},
90
+ "execution_count" : 5
91
+ }
92
+ ]
93
+ },
94
+ {
95
+ "cell_type" : " code" ,
96
+ "source" : [
97
+ " len(d_data)"
98
+ ],
99
+ "metadata" : {
100
+ "colab" : {
101
+ "base_uri" : " https://localhost:8080/"
102
+ },
103
+ "id" : " JrhYpQ3ixt7U" ,
104
+ "outputId" : " da1ea047-ef97-46e8-cfdd-0092e2ff51f1"
105
+ },
106
+ "execution_count" : 6 ,
107
+ "outputs" : [
108
+ {
109
+ "output_type" : " execute_result" ,
110
+ "data" : {
111
+ "text/plain" : [
112
+ " 4"
113
+ ]
114
+ },
115
+ "metadata" : {},
116
+ "execution_count" : 6
117
+ }
118
+ ]
119
+ },
120
+ {
121
+ "cell_type" : " code" ,
122
+ "source" : [
123
+ " for key in d_data:\n " ,
124
+ " print(key,d_data[key])"
125
+ ],
126
+ "metadata" : {
127
+ "colab" : {
128
+ "base_uri" : " https://localhost:8080/"
129
+ },
130
+ "id" : " Y7QnYISpx0lx" ,
131
+ "outputId" : " 0e112f96-2558-4720-e75d-b256c3e4708a"
132
+ },
133
+ "execution_count" : 7 ,
134
+ "outputs" : [
135
+ {
136
+ "output_type" : " stream" ,
137
+ "name" : " stdout" ,
138
+ "text" : [
139
+ " 1 ammu\n " ,
140
+ " 2 aji\n " ,
141
+ " 3 aju\n " ,
142
+ " 4 ammini\n "
143
+ ]
144
+ }
145
+ ]
146
+ },
147
+ {
148
+ "cell_type" : " code" ,
149
+ "source" : [
150
+ " for key,value in d_data.items():\n " ,
151
+ " print(key,value)"
152
+ ],
153
+ "metadata" : {
154
+ "colab" : {
155
+ "base_uri" : " https://localhost:8080/"
156
+ },
157
+ "id" : " Kduh4qfNyA4d" ,
158
+ "outputId" : " 815a076e-ea65-4804-f84f-872949b23eb8"
159
+ },
160
+ "execution_count" : 10 ,
161
+ "outputs" : [
162
+ {
163
+ "output_type" : " stream" ,
164
+ "name" : " stdout" ,
165
+ "text" : [
166
+ " 1 ammu\n " ,
167
+ " 2 aji\n " ,
168
+ " 3 aju\n " ,
169
+ " 4 ammini\n "
170
+ ]
171
+ }
172
+ ]
173
+ },
174
+ {
175
+ "cell_type" : " code" ,
176
+ "source" : [
177
+ " print(d_data.items())"
178
+ ],
179
+ "metadata" : {
180
+ "colab" : {
181
+ "base_uri" : " https://localhost:8080/"
182
+ },
183
+ "id" : " 4FeMO3NpyNO6" ,
184
+ "outputId" : " a6e9f162-fe75-4ef3-95af-e1a4c0313404"
185
+ },
186
+ "execution_count" : 11 ,
187
+ "outputs" : [
188
+ {
189
+ "output_type" : " stream" ,
190
+ "name" : " stdout" ,
191
+ "text" : [
192
+ " dict_items([(1, 'ammu'), (2, 'aji'), (3, 'aju'), (4, 'ammini')])\n "
193
+ ]
194
+ }
195
+ ]
196
+ },
197
+ {
198
+ "cell_type" : " code" ,
199
+ "source" : [
200
+ " d_data[9]=\" akkki\"\n " ,
201
+ " print(d_data)"
202
+ ],
203
+ "metadata" : {
204
+ "colab" : {
205
+ "base_uri" : " https://localhost:8080/"
206
+ },
207
+ "id" : " 2__ddPcCyWMQ" ,
208
+ "outputId" : " 801ddb8f-7138-4f2a-8a69-51753bbb0e7b"
209
+ },
210
+ "execution_count" : 12 ,
211
+ "outputs" : [
212
+ {
213
+ "output_type" : " stream" ,
214
+ "name" : " stdout" ,
215
+ "text" : [
216
+ " {1: 'ammu', 2: 'aji', 3: 'aju', 4: 'ammini', 9: 'akkki'}\n "
217
+ ]
218
+ }
219
+ ]
220
+ },
221
+ {
222
+ "cell_type" : " markdown" ,
223
+ "source" : [
224
+ " # A **set** in Python is an unordered collection of unique elements. It is useful for removing duplicates and performing set operations like union, intersection, and difference."
225
+ ],
226
+ "metadata" : {
227
+ "id" : " An9QYOX3yyw2"
228
+ }
229
+ },
230
+ {
231
+ "cell_type" : " code" ,
232
+ "source" : [
233
+ " a=[1,8,3,22,6,22,8,2]\n " ,
234
+ " print(a)\n " ,
235
+ " b= set(a)\n " ,
236
+ " print(b)"
237
+ ],
238
+ "metadata" : {
239
+ "colab" : {
240
+ "base_uri" : " https://localhost:8080/"
241
+ },
242
+ "id" : " anybva2My3jm" ,
243
+ "outputId" : " d9f5cd78-53da-4e63-9651-bd830656de24"
244
+ },
245
+ "execution_count" : 13 ,
246
+ "outputs" : [
247
+ {
248
+ "output_type" : " stream" ,
249
+ "name" : " stdout" ,
250
+ "text" : [
251
+ " [1, 8, 3, 22, 6, 22, 8, 2]\n " ,
252
+ " {1, 2, 3, 6, 8, 22}\n "
253
+ ]
254
+ }
255
+ ]
256
+ }
257
+ ]
258
+ }
0 commit comments