All language subtitles for 37. Dictionary Methods

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,420 --> 00:00:01,650 Welcome back. 2 00:00:01,680 --> 00:00:07,330 Now if you remember let's have something different here so we have unique keys. 3 00:00:07,380 --> 00:00:09,880 If you remember we have to have a unique keys. 4 00:00:09,900 --> 00:00:18,360 So let's say this is great and this is a I don't know let's say a basket and we can access basket like 5 00:00:18,360 --> 00:00:22,700 this if I click Run get one two three. 6 00:00:22,770 --> 00:00:25,830 But what if we don't know what this dictionary is. 7 00:00:25,830 --> 00:00:32,640 Maybe a dictionary is something well somewhere else where we can't see but we want to know if this let's 8 00:00:32,640 --> 00:00:34,470 call this user. 9 00:00:34,470 --> 00:00:45,140 If this user has maybe property like H So do they have this H key. 10 00:00:45,320 --> 00:00:46,490 Well if I click Run 11 00:00:49,360 --> 00:00:51,160 I get an error key error. 12 00:00:51,160 --> 00:00:58,990 H H doesn't exist but remember errors in our programs and this is something we'll cover later on are 13 00:00:59,080 --> 00:00:59,930 not good. 14 00:00:59,990 --> 00:01:05,490 They're going to stop the program as soon as the python interpreters enters an error. 15 00:01:05,560 --> 00:01:11,200 It's going to kick out of the program and say hey you have an error and it's going to completely ignore 16 00:01:11,200 --> 00:01:16,540 what's underneath it here we don't have anything but in a real life program we want to avoid these errors 17 00:01:16,570 --> 00:01:18,780 because it stops execution. 18 00:01:18,820 --> 00:01:26,520 So another good way to access a key and to see if it even exists is to use dot get and guess what does 19 00:01:26,560 --> 00:01:29,910 get is did you guess a method. 20 00:01:29,910 --> 00:01:31,320 Well there you go. 21 00:01:31,350 --> 00:01:39,160 Dog get is a method on the object or the dictionary in Python. 22 00:01:39,270 --> 00:01:50,020 So here if we do get age and do run I get none. 23 00:01:50,090 --> 00:01:51,720 So my program doesn't error. 24 00:01:51,740 --> 00:01:54,200 It just says hey there is nothing there. 25 00:01:54,260 --> 00:01:55,490 It's an absence of value. 26 00:01:55,610 --> 00:01:57,970 And we've learned what none means by now. 27 00:01:58,040 --> 00:02:02,330 So that's a really nice way to avoid those errors by the way. 28 00:02:02,330 --> 00:02:06,920 If let's say there's no age in the user but you want to have a default value. 29 00:02:06,920 --> 00:02:08,290 You can do something like this. 30 00:02:08,390 --> 00:02:16,510 So you add a comma and then here you say whatever you want as the default value so let's forget that. 31 00:02:16,790 --> 00:02:20,990 If I click Run I get 55. 32 00:02:21,610 --> 00:02:29,440 Because now I'm saying Hey grab the h from the user dictionary if age doesn't exist on the user dictionary 33 00:02:29,710 --> 00:02:31,120 use 55. 34 00:02:31,150 --> 00:02:42,550 So now we have 55 but if the user already has age and I click Run I get 20. 35 00:02:42,600 --> 00:02:50,190 So this is Hey in case age doesn't exist at a default value that's really really nice. 36 00:02:50,190 --> 00:02:55,140 Now I'm going to show you another way to create a dictionary which is not very common in most of the 37 00:02:55,140 --> 00:02:59,550 time you want to use this syntax but just so you're aware of it. 38 00:02:59,670 --> 00:03:01,050 Here's another way. 39 00:03:01,050 --> 00:03:05,870 Let's say we have a new user so User 2. 40 00:03:06,480 --> 00:03:13,890 I can create here a dictionary by saying dict which again is a built in function. 41 00:03:13,890 --> 00:03:15,750 And in here look at that. 42 00:03:15,750 --> 00:03:20,640 It shows me Hey this is going to create a new empty dictionary and we can create different values key 43 00:03:20,640 --> 00:03:29,970 variable value pairs and we simply say I want the key to equal the value. 44 00:03:29,970 --> 00:03:35,740 So in my case let's just say that I want the name to equal 45 00:03:39,000 --> 00:03:49,180 if I now print out user to well before I click Run I see that I have a red underline and by the way 46 00:03:49,210 --> 00:03:50,800 if you see here pi flakes. 47 00:03:50,920 --> 00:03:55,840 That's something called linking something we'll talk about when we talk about developer environments. 48 00:03:55,840 --> 00:04:01,090 We're using this Lintner that tells you whenever you make errors in Python and it says keywords can 49 00:04:01,090 --> 00:04:10,450 be an expression that just means that hey the keyword needs to be well just a variable that we create. 50 00:04:10,460 --> 00:04:21,310 So if I click Run here look at that I have name John John so we've create a user with this key value 51 00:04:21,550 --> 00:04:22,480 pair. 52 00:04:22,720 --> 00:04:27,430 Now like I said this way of creating dictionaries is not very common. 53 00:04:27,430 --> 00:04:32,380 Most of the time you'll do something like this but at least now you know that this is why this built 54 00:04:32,380 --> 00:04:36,250 in function exists I'll see in the next one. 55 00:04:36,510 --> 00:04:36,740 By. 5389

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