All language subtitles for 38. Dictionary Methods 2

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian Download
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,860 --> 00:00:08,720 By the way there is actually one more way that we've actually seen in list how to look for an item in 2 00:00:08,720 --> 00:00:17,750 a dictionary remember how in lists we use the keyword in we said something along the lines of Hey is 3 00:00:17,840 --> 00:00:27,140 I in a list that contains I or we even used a string like Hi. 4 00:00:27,180 --> 00:00:30,030 Well you can do the same with dictionaries. 5 00:00:30,030 --> 00:00:37,190 I can say does basket exist in user and let's print this out. 6 00:00:40,840 --> 00:00:46,330 And run and it's going to say yep basket does exists in user. 7 00:00:46,530 --> 00:00:50,780 What about what about the size. 8 00:00:50,840 --> 00:00:52,580 Does that exist. 9 00:00:52,580 --> 00:00:53,540 No that's false. 10 00:00:53,540 --> 00:00:55,860 That does not exist in user. 11 00:00:56,150 --> 00:00:59,630 But here is where it gets really interesting. 12 00:00:59,660 --> 00:01:05,270 And this again is a nother dictionary method that we can use. 13 00:01:05,330 --> 00:01:13,610 And by the way you can see that there's not that many dictionary methods that well dictionaries have. 14 00:01:13,610 --> 00:01:24,270 Luckily we're gonna go over the main ones here though one is called Quis and keys simply checks the 15 00:01:24,270 --> 00:01:25,250 keys. 16 00:01:25,350 --> 00:01:27,180 What are the keys of user. 17 00:01:27,180 --> 00:01:36,680 So if I go Hello here and I click Run well no keys ha sorry on this side not this. 18 00:01:36,690 --> 00:01:38,560 So this is a value. 19 00:01:38,790 --> 00:01:48,850 So if I want to check keys I'd say H which is true but if I want to check a values well in that case 20 00:01:48,850 --> 00:01:49,440 if I do. 21 00:01:49,440 --> 00:02:01,960 Hello I get true it's going to go over or what we call iterate over the values another one that's really 22 00:02:01,960 --> 00:02:11,050 useful is the items and items is special because we've seen keys and values but items actually grabs 23 00:02:11,170 --> 00:02:14,260 the entire item. 24 00:02:14,360 --> 00:02:23,020 So the way we can actually see this is let's just remove and click Run All right. 25 00:02:23,040 --> 00:02:24,240 This is interesting. 26 00:02:24,240 --> 00:02:35,080 I have dict items here and I grab looks like a list and in here we have a bracket basket. 27 00:02:35,080 --> 00:02:42,130 One two three greet hello and H20 but there's some weird syntax here that we haven't seen before and 28 00:02:42,220 --> 00:02:44,250 this is actually a topple. 29 00:02:44,260 --> 00:02:49,030 So we're going to hold off on this and talk about this a little bit more when we talk about our next 30 00:02:49,180 --> 00:02:57,220 data structure but keys values and items is an easy way for us to grab these things for us from our 31 00:02:57,220 --> 00:03:02,610 dictionary let's continue on with other dictionary methods that we might use. 32 00:03:02,750 --> 00:03:04,590 One is a very nice one. 33 00:03:04,670 --> 00:03:07,650 It's called Clear. 34 00:03:08,020 --> 00:03:13,710 And if I run this you'll see that I get an empty dictionary. 35 00:03:13,900 --> 00:03:19,400 What if I just run users dot clear here and run. 36 00:03:19,480 --> 00:03:31,350 User Well it's still an empty object or an empty dictionary so you can see here that clear doesn't actually 37 00:03:31,350 --> 00:03:32,610 return anything. 38 00:03:32,640 --> 00:03:33,380 It doesn't. 39 00:03:33,390 --> 00:03:38,050 Well it is just in place removes whatever the dictionary has. 40 00:03:38,070 --> 00:03:40,350 So it just creates an empty dictionary. 41 00:03:42,140 --> 00:03:56,350 What about copy while a copy allows us to copy a user so that if I print user and user 2 and I click 42 00:03:56,470 --> 00:04:01,470 Run I get two users each. 43 00:04:01,590 --> 00:04:03,390 Keys and values copy. 44 00:04:03,390 --> 00:04:14,210 But if I now let's say clear the first user and I click Run the first user is empty but because I've 45 00:04:14,230 --> 00:04:21,930 copied the second user the second user has the old information and this is a concept that we've talked 46 00:04:21,930 --> 00:04:22,850 about before. 47 00:04:24,620 --> 00:04:34,250 Another useful command and let's just go back to having user is user dot pop which removes a key and 48 00:04:34,250 --> 00:04:36,180 a value from the dictionary. 49 00:04:36,200 --> 00:04:45,260 So in our case let's just say we want to remove the key that is age so I'm going to say h and if I run 50 00:04:45,260 --> 00:04:52,220 this I get 20 because pop returns the value of whatever got removed. 51 00:04:52,410 --> 00:05:00,610 But if I do print user now you'll see that age does not exist anymore because we've popped it off but 52 00:05:00,610 --> 00:05:08,730 pop as you can see removes the actual value or returns the actual value 20. 53 00:05:08,780 --> 00:05:12,090 Here's another really fun one pop item. 54 00:05:12,320 --> 00:05:18,440 And honestly this I having used much but I just think it's a fun one pop item. 55 00:05:18,440 --> 00:05:26,330 If you guessed Well you're not gonna guess oh and that's because I have to make sure I write it properly 56 00:05:26,510 --> 00:05:36,140 with lowercase if I run this would just happened it randomly pops off something one of the keys and 57 00:05:36,140 --> 00:05:39,490 the values in this case age 20 is removed. 58 00:05:39,490 --> 00:05:45,820 So the last item on the dictionary gets removed by remember a dictionary is unordered. 59 00:05:45,860 --> 00:05:54,680 So if this was a massive massive dictionary that well doesn't have any order to it sometimes it removes 60 00:05:55,250 --> 00:06:03,620 some pear as you can see not the last one but some pair of key value so you have to be careful with 61 00:06:03,620 --> 00:06:04,100 this one. 62 00:06:04,100 --> 00:06:10,680 It doesn't necessarily just remove the last thing that you entered but it might be useful on some occasions. 63 00:06:10,700 --> 00:06:19,630 Finally we have something called update an update simply updates as the name suggests a key value so 64 00:06:20,020 --> 00:06:20,830 let's have a look here. 65 00:06:21,280 --> 00:06:29,470 All we have to do is give it a new dictionary so curly brackets and just simply say hey I want to update 66 00:06:29,650 --> 00:06:39,390 age to fifty five fight click Run Oh and I forgot a bracket here. 67 00:06:39,390 --> 00:06:40,140 Let's try that again. 68 00:06:40,140 --> 00:06:42,880 If I click Run. 69 00:06:43,070 --> 00:06:43,790 There you go. 70 00:06:43,790 --> 00:06:54,000 Age got updated but if this was a key that doesn't exist like ages and I click run it will still update 71 00:06:54,840 --> 00:06:56,330 with a new key item. 72 00:06:57,310 --> 00:07:00,460 So this is another really useful method. 73 00:07:00,490 --> 00:07:02,850 All right that's it for dictionaries. 74 00:07:02,860 --> 00:07:04,140 I'll see you in the next video. 7308

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.