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
📚
LearningTranscript
00:00Welcome back guys and Carly's
00:06In this lecture we will be most used methods
00:09because we can apply to the dictionary
00:124 fundamental methods
00:15which you will use 80% of the time
00:18We will discuss it
00:20First of all, we have a get method
00:22Now I will show you the problem
00:24and then I will show you the solution
00:26how to provide
00:28Now, normally
00:32when we have any value
00:34we will use the key
00:36For example, I will enter
00:38and I will say bonus
00:40No big deal
00:42I will call
00:44No big deal
00:46I will wrap up
00:48I will say two lives
00:50Very good
00:52I will say weapons
00:54Weapons
00:56Run
00:58This gives me error
01:00This gives me error
01:02What is the error?
01:04What is the error?
01:06Weapon exist
01:07No problem
01:08Very good
01:10However, I will say
01:12Print or
01:14This is rest of the code
01:16This is the code
01:18This is the game
01:19This is the code
01:20This is the code
01:22So the rest of the code
01:24Basically, you can see here
01:26Right?
01:28Here we go
01:30Here is the code
01:32Right?
01:34This means that the code is in line 12. It's not executed.
01:41This means that if it exists, it doesn't exist.
01:47If it exists, it doesn't exist.
01:50This means that the code is executed.
01:53This is important.
01:54So, this is for get method.
01:56We call get.
01:57We call round braces.
02:01We call it and run.
02:03Now, get weapons.
02:05We call it execute.
02:07Get weapons.
02:09We call it execute.
02:11This is the get method.
02:15This is another method.
02:19We call it keys.
02:23We call it keys.
02:27If you print the keys, then guess what?
02:31You can execute the keys.
02:33As you see, you have a list of keys.
02:36You can print the values.
02:39You can execute the values.
02:42Instead of keys, you get the values.
02:44Name, fold to likes.
02:45If you want to create all the items in form of a list, then you call it items.
02:53Run.
02:54And you get a list of key value pairs.
02:57They are in form of tuple.
02:59We discuss in the next lecture.
03:01At the moment, you can see key values, items and get.
03:06Which is very important.
03:08Now, you have to think about it.
03:10One is the key word.
03:12Basically, we check whether an item exists or not exists.
03:19Imagine.
03:20I want to check whether weapon exists in the characteristics.
03:24If I say this, weapon, weapons.
03:29Okay?
03:30Okay?
03:31Now, I need to check in the keys.
03:32The key points in the inside of the weapon exists.
03:35Of course, I will put it up.
03:38Okay?
03:39I will call it keys.
03:41I will call it keys.
03:42Because keys, I need to check in keys.
03:44I need to check in keys.
03:45The key word is in.
03:47It is basically in.
03:50It is in dictionary.
03:52It is not to check in the key.
03:54It is true.
03:55It is false.
03:56If it is true, then it is false.
03:58case میں weapon exist نہیں کرتا تو
03:59ہم expect کر رہے ہیں کہ یہ ہمیں false return کرے گا
04:01تو چلیے دیکھتے ہیں and kaboom
04:03shaka اور laqa
04:05کہ یہ کہہ رہا ہے کہ ہمارے پاس
04:07false یعنی کہ weapon exist نہیں کرتا
04:09let's check bonus کیا bonus exist
04:11کرتا ہے
04:12run it
04:14true bonus exist کرتا ہے
04:17چلے full check کرتے ہیں
04:19کیا full exist کرتا ہے run کرتے ہیں
04:21full false
04:23کیونکہ full ہمارے پاس
04:25values میں exist کرتا ہے
04:27اسی کو اگر آپ change کر دینا values
04:29now it will return true
04:30یہ دیکھئے now it will return true
04:33تو آپ نے دیکھا کہ
04:35کتنا آسانی کے ساتھ ہم
04:37ان چار functions کو use کر کے
04:39dictionaries کو
04:41manipulate change اور
04:42ان کے اندر جو ہے
04:45changes کر سکتے ہیں
04:46اب میں اس لیکچر کو یہاں پہ
04:49ایک اور bonus method
04:51کے اوپر close کرنے لگا ہوں
04:52اور وہ ہے pop item
04:55آپ کو یاد ہوگا
04:57کہ list کے اندر جب ہم pop
04:59کرتے تھے تو آخری آخری element
05:01pop ہو جاتا تھا
05:02اب جب میں کہتا ہوں
05:04آخری تو اس کا مطلب یہ ہے
05:05کہ اس کی کوئی location ہے
05:06اس کی کوئی position ہے
05:07تب ہی تو آخری کہہ رہا ہوں
05:08تب ہی تو آخری کہہ رہا ہوں
05:10کیونکہ مجھے پتہ ہے
05:11کہ وہ آخری ہے
05:12however dictionary بھی تو
05:14کوئی location ہی نہیں ہوتی
05:15تو اگر میں dictionary کے اوپر
05:17pop item کا method call کرتا ہوں
05:19let's say like this
05:21pop items
05:22item
05:24آپ کے خیال سے کونسا
05:26pop ہو جائے گا
05:28item
05:29آخری ہوگا
05:30پہلا ہوگا کونسا ہوگا
05:31چلیے دیکھتے ہیں
05:33میں اس کو run کرتا ہوں
05:34and we get bonus
05:37is equal to two lives
05:38item pop ہوا
05:39چلیے میں dictionary کو
05:42دوبارہ print کرتا ہوں
05:43دیکھتے ہیں ہماری dictionary
05:43سلامت ہے کہ نہیں
05:46dictionary
05:47d i c
05:47t i o
05:49d i c
05:50t i o
05:50n a
05:51r y dictionary
05:52execute
05:53ہماری dictionary میں سے
05:55جو ہے وہ
05:57pop ہو گیا
05:57bonus
05:58makes sense
05:59bonus ہمارا last element تھا
06:01چلیے یہ اس طرح کرتے ہیں
06:02دوبارہ کرتے ہیں
06:04and
06:06we get the same result
06:07however
06:07جب آپ کے پاس
06:09dictionary بڑی ہو جاتی ہے
06:10then
06:12becomes the problem
06:13اس کی ریزن یہ ہے
06:14کیونکہ
06:15dictionaries
06:16unordered ہوتی ہیں
06:19تو
06:20it's not always true
06:22کہ final element
06:23جو ہے
06:23وہ ہی
06:24ہمیشہ
06:25pop ہوگا
06:26it's not always true
06:27مثال کے طور پہ
06:28یہ دیکھئے
06:29یہ player one
06:30bonus ہے
06:31then
06:31میں اس کو
06:32two کر دیتا ہوں
06:33اس کو بھی
06:34two کر دیتے ہیں
06:35and two
06:36and let's make it
06:37three
06:37and
06:39three
06:39and three
06:41let's make it
06:42four
06:42and four
06:44and
06:45so on
06:46ٹھیک ہے
06:46تو یہ صرف
06:47میں نے
06:47dictionary بڑی کر دیا ہے
06:49just to make you
06:50see
06:50کہ
06:50if
06:51this is always
06:52anyway
06:53I've made it
06:54some mistake
06:54okay
06:56میں نے
06:56یہاں پہ
06:57کاما نہیں
06:57ڈالا
06:57ٹھیک ہے
06:58اور یہاں پہ
07:00بھی نہیں
07:00ڈالا
07:00ہو
07:00by the way
07:01copy کرنے
07:01یہی نقصان
07:02ہوتا ہے
07:02and you can
07:03see
07:04ٹھیک ہے
07:05okay
07:05now let's run
07:06it again
07:06now
07:08bonus five
07:10two lives
07:10remove ہوا
07:11and
07:12we see the same
07:14however
07:14آپ نے
07:15اس چیز
07:16کا خیال
07:16رکھنا ہے
07:17کہ
07:17it's not
07:17always true
07:18کہ pop item
07:19جو ہے
07:19وہ ہمیشہ
07:20last element
07:21جو ہے
07:21وہ
07:21نکالے گا
07:22اس کی ریزن یہ ہے
07:23وہ ہمیشہ
07:24last element
07:25جو ہے
07:25وہ
07:25نکالے گا
07:26اس کی ریزن یہ ہے
07:27کہ
07:27جیسا کہ
07:29dictionaries
07:30unordered ہوتی ہیں
07:31python
07:32اپنی مرضی سے
07:32ان کو
07:32memory کے اندر
07:33save کرتا ہے
07:34تو
07:34it's not
07:35always true
07:36کہ جو
07:36last element
07:37ہے وہ
07:37ہمیشہ
07:37memory کے
07:38last address
07:38پہ save
07:39ہو
07:39just a small tip
07:40ٹھیک ہے
07:40okay
07:41close کرتے ہیں
07:42آپ
07:42اس لیکن
07:42ٹھیک ہے
07:43آپ
07:44یں
07:44Deutschland