Skip to player
Skip to main content
Skip to footer
Search
Connect
Watch fullscreen
Like
Comments
Bookmark
Share
Add to Playlist
Report
Lecture 44: Most Used Dictionary Methods in Python
Nafees AI Lab
Follow
5/18/2025
Python dictionaries store data in key-value pairs, where each key must be unique and immutable (e.g., strings, numbers, tuples). The values, however, can be of any data type and can be duplicated.
Category
📚
Learning
Transcript
Display full video transcript
00:00
Welcome back guys and Carly's
00:06
In this lecture we will be most used methods
00:09
because we can apply to the dictionary
00:12
4 fundamental methods
00:15
which you will use 80% of the time
00:18
We will discuss it
00:20
First of all, we have a get method
00:22
Now I will show you the problem
00:24
and then I will show you the solution
00:26
how to provide
00:28
Now, normally
00:32
when we have any value
00:34
we will use the key
00:36
For example, I will enter
00:38
and I will say bonus
00:40
No big deal
00:42
I will call
00:44
No big deal
00:46
I will wrap up
00:48
I will say two lives
00:50
Very good
00:52
I will say weapons
00:54
Weapons
00:56
Run
00:58
This gives me error
01:00
This gives me error
01:02
What is the error?
01:04
What is the error?
01:06
Weapon exist
01:07
No problem
01:08
Very good
01:10
However, I will say
01:12
Print or
01:14
This is rest of the code
01:16
This is the code
01:18
This is the game
01:19
This is the code
01:20
This is the code
01:22
So the rest of the code
01:24
Basically, you can see here
01:26
Right?
01:28
Here we go
01:30
Here is the code
01:32
Right?
01:34
This means that the code is in line 12. It's not executed.
01:41
This means that if it exists, it doesn't exist.
01:47
If it exists, it doesn't exist.
01:50
This means that the code is executed.
01:53
This is important.
01:54
So, this is for get method.
01:56
We call get.
01:57
We call round braces.
02:01
We call it and run.
02:03
Now, get weapons.
02:05
We call it execute.
02:07
Get weapons.
02:09
We call it execute.
02:11
This is the get method.
02:15
This is another method.
02:19
We call it keys.
02:23
We call it keys.
02:27
If you print the keys, then guess what?
02:31
You can execute the keys.
02:33
As you see, you have a list of keys.
02:36
You can print the values.
02:39
You can execute the values.
02:42
Instead of keys, you get the values.
02:44
Name, fold to likes.
02:45
If you want to create all the items in form of a list, then you call it items.
02:53
Run.
02:54
And you get a list of key value pairs.
02:57
They are in form of tuple.
02:59
We discuss in the next lecture.
03:01
At the moment, you can see key values, items and get.
03:06
Which is very important.
03:08
Now, you have to think about it.
03:10
One is the key word.
03:12
Basically, we check whether an item exists or not exists.
03:19
Imagine.
03:20
I want to check whether weapon exists in the characteristics.
03:24
If I say this, weapon, weapons.
03:29
Okay?
03:30
Okay?
03:31
Now, I need to check in the keys.
03:32
The key points in the inside of the weapon exists.
03:35
Of course, I will put it up.
03:38
Okay?
03:39
I will call it keys.
03:41
I will call it keys.
03:42
Because keys, I need to check in keys.
03:44
I need to check in keys.
03:45
The key word is in.
03:47
It is basically in.
03:50
It is in dictionary.
03:52
It is not to check in the key.
03:54
It is true.
03:55
It is false.
03:56
If it is true, then it is false.
03:58
case میں weapon exist نہیں کرتا تو
03:59
ہم expect کر رہے ہیں کہ یہ ہمیں false return کرے گا
04:01
تو چلیے دیکھتے ہیں and kaboom
04:03
shaka اور laqa
04:05
کہ یہ کہہ رہا ہے کہ ہمارے پاس
04:07
false یعنی کہ weapon exist نہیں کرتا
04:09
let's check bonus کیا bonus exist
04:11
کرتا ہے
04:12
run it
04:14
true bonus exist کرتا ہے
04:17
چلے full check کرتے ہیں
04:19
کیا full exist کرتا ہے run کرتے ہیں
04:21
full false
04:23
کیونکہ full ہمارے پاس
04:25
values میں exist کرتا ہے
04:27
اسی کو اگر آپ change کر دینا values
04:29
now it will return true
04:30
یہ دیکھئے now it will return true
04:33
تو آپ نے دیکھا کہ
04:35
کتنا آسانی کے ساتھ ہم
04:37
ان چار functions کو use کر کے
04:39
dictionaries کو
04:41
manipulate change اور
04:42
ان کے اندر جو ہے
04:45
changes کر سکتے ہیں
04:46
اب میں اس لیکچر کو یہاں پہ
04:49
ایک اور bonus method
04:51
کے اوپر close کرنے لگا ہوں
04:52
اور وہ ہے pop item
04:55
آپ کو یاد ہوگا
04:57
کہ list کے اندر جب ہم pop
04:59
کرتے تھے تو آخری آخری element
05:01
pop ہو جاتا تھا
05:02
اب جب میں کہتا ہوں
05:04
آخری تو اس کا مطلب یہ ہے
05:05
کہ اس کی کوئی location ہے
05:06
اس کی کوئی position ہے
05:07
تب ہی تو آخری کہہ رہا ہوں
05:08
تب ہی تو آخری کہہ رہا ہوں
05:10
کیونکہ مجھے پتہ ہے
05:11
کہ وہ آخری ہے
05:12
however dictionary بھی تو
05:14
کوئی location ہی نہیں ہوتی
05:15
تو اگر میں dictionary کے اوپر
05:17
pop item کا method call کرتا ہوں
05:19
let's say like this
05:21
pop items
05:22
item
05:24
آپ کے خیال سے کونسا
05:26
pop ہو جائے گا
05:28
item
05:29
آخری ہوگا
05:30
پہلا ہوگا کونسا ہوگا
05:31
چلیے دیکھتے ہیں
05:33
میں اس کو run کرتا ہوں
05:34
and we get bonus
05:37
is equal to two lives
05:38
item pop ہوا
05:39
چلیے میں dictionary کو
05:42
دوبارہ print کرتا ہوں
05:43
دیکھتے ہیں ہماری dictionary
05:43
سلامت ہے کہ نہیں
05:46
dictionary
05:47
d i c
05:47
t i o
05:49
d i c
05:50
t i o
05:50
n a
05:51
r y dictionary
05:52
execute
05:53
ہماری dictionary میں سے
05:55
جو ہے وہ
05:57
pop ہو گیا
05:57
bonus
05:58
makes sense
05:59
bonus ہمارا last element تھا
06:01
چلیے یہ اس طرح کرتے ہیں
06:02
دوبارہ کرتے ہیں
06:04
and
06:06
we get the same result
06:07
however
06:07
جب آپ کے پاس
06:09
dictionary بڑی ہو جاتی ہے
06:10
then
06:12
becomes the problem
06:13
اس کی ریزن یہ ہے
06:14
کیونکہ
06:15
dictionaries
06:16
unordered ہوتی ہیں
06:19
تو
06:20
it's not always true
06:22
کہ final element
06:23
جو ہے
06:23
وہ ہی
06:24
ہمیشہ
06:25
pop ہوگا
06:26
it's not always true
06:27
مثال کے طور پہ
06:28
یہ دیکھئے
06:29
یہ player one
06:30
bonus ہے
06:31
then
06:31
میں اس کو
06:32
two کر دیتا ہوں
06:33
اس کو بھی
06:34
two کر دیتے ہیں
06:35
and two
06:36
and let's make it
06:37
three
06:37
and
06:39
three
06:39
and three
06:41
let's make it
06:42
four
06:42
and four
06:44
and
06:45
so on
06:46
ٹھیک ہے
06:46
تو یہ صرف
06:47
میں نے
06:47
dictionary بڑی کر دیا ہے
06:49
just to make you
06:50
see
06:50
کہ
06:50
if
06:51
this is always
06:52
anyway
06:53
I've made it
06:54
some mistake
06:54
okay
06:56
میں نے
06:56
یہاں پہ
06:57
کاما نہیں
06:57
ڈالا
06:57
ٹھیک ہے
06:58
اور یہاں پہ
07:00
بھی نہیں
07:00
ڈالا
07:00
ہو
07:00
by the way
07:01
copy کرنے
07:01
یہی نقصان
07:02
ہوتا ہے
07:02
and you can
07:03
see
07:04
ٹھیک ہے
07:05
okay
07:05
now let's run
07:06
it again
07:06
now
07:08
bonus five
07:10
two lives
07:10
remove ہوا
07:11
and
07:12
we see the same
07:14
however
07:14
آپ نے
07:15
اس چیز
07:16
کا خیال
07:16
رکھنا ہے
07:17
کہ
07:17
it's not
07:17
always true
07:18
کہ pop item
07:19
جو ہے
07:19
وہ ہمیشہ
07:20
last element
07:21
جو ہے
07:21
وہ
07:21
نکالے گا
07:22
اس کی ریزن یہ ہے
07:23
وہ ہمیشہ
07:24
last element
07:25
جو ہے
07:25
وہ
07:25
نکالے گا
07:26
اس کی ریزن یہ ہے
07:27
کہ
07:27
جیسا کہ
07:29
dictionaries
07:30
unordered ہوتی ہیں
07:31
python
07:32
اپنی مرضی سے
07:32
ان کو
07:32
memory کے اندر
07:33
save کرتا ہے
07:34
تو
07:34
it's not
07:35
always true
07:36
کہ جو
07:36
last element
07:37
ہے وہ
07:37
ہمیشہ
07:37
memory کے
07:38
last address
07:38
پہ save
07:39
ہو
07:39
just a small tip
07:40
ٹھیک ہے
07:40
okay
07:41
close کرتے ہیں
07:42
آپ
07:42
اس لیکن
07:42
ٹھیک ہے
07:43
آپ
07:44
یں
07:44
Deutschland
Recommended
5:10
|
Up next
Lecture 43: Python has Un-changeable dic key
Nafees AI Lab
5/18/2025
8:48
Lecture 42: Dictionary in Python Language
Nafees AI Lab
5/18/2025
11:19
Lecture 53: Python has for loop and Iterables
Nafees AI Lab
5/20/2025
9:59
Lecture 37: Python has Data Structor and Lists-II
Nafees AI Lab
5/17/2025
8:19
Lecture 36: Python has Data Structor and Lists
Nafees AI Lab
5/17/2025
2:54
Lecture 34: Python has Boolean Data Type
Nafees AI Lab
5/16/2025
3:23
Lecture 79: Sets and Dictionary Comprehension in Python
Nafees AI Lab
5/23/2025
4:52
Lecture 50: Python with Boolean values
Nafees AI Lab
5/18/2025
10:23
Lecture 78: List Comprehension in Python
Nafees AI Lab
5/23/2025
6:49
Lecture 74: Python has Special Function Map
Nafees AI Lab
5/23/2025
0:27
Making waterproof shoes with duct tape! 👌🏞️
MetDaan Creative
5 days ago
0:16
When it's your boyfriend's laundry day! 😅🤣
MetDaan Creative
5 days ago
0:24
Spreading chocolate cream with a plaster! 😅🍞
MetDaan Creative
5 days ago
7:40
Mera Mazloom Hussain | Nadeem Sarwar 2020 | 1442
Gham-e-Hussain | غمِ حسینؑ
6/9/2025
9:38
Episode 1 – The Curious Boy from Ulm (1879-1895)
Nafees AI Lab
6/8/2025
0:37
Top Fully Funded Scholarships in Germany 2025 🇩🇪 | Apply Now!
Nafees AI Lab
6/3/2025
0:25
The Boy and the Dragon – “A Friend in the Sky”
Nafees AI Lab
6/3/2025
1:03
Why Do Rainbows Appear? 🌈 | Physics in Everyday Life
Nafees AI Lab
6/3/2025
0:28
Albert Einstein: The Genius Who Changed Time
Nafees AI Lab
6/1/2025
0:40
Stephen Hawking’s Life in 60 Seconds: From Wheelchair to the Universe
Nafees AI Lab
6/1/2025
0:36
The Forgotten Night Hitler Was Nearly Killed
Nafees AI Lab
5/29/2025
0:31
Dilip Kumar – The Tragedy King of Bollywood
Nafees AI Lab
5/29/2025
0:45
Marlon Brando – The Rebel Who Redefined Acting | Nafees AI Lab
Nafees AI Lab
5/29/2025
0:29
Charles Darwin – Evolution & Natural Selection | Nafees AI Lab
Nafees AI Lab
5/28/2025
0:30
Isaac Newton – Gravity, Motion & Genius | Nafees AI Lab
Nafees AI Lab
5/28/2025