All language subtitles for 37. Dictionary Methods

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
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
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

Welcome back.

Now if you remember let's have something different here so we have unique keys.

If you remember we have to have a unique keys.

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

this if I click Run get one two three.

But what if we don't know what this dictionary is.

Maybe a dictionary is something well somewhere else where we can't see but we want to know if this let's

call this user.

If this user has maybe property like H So do they have this H key.

Well if I click Run

I get an error key error.

H H doesn't exist but remember errors in our programs and this is something we'll cover later on are

not good.

They're going to stop the program as soon as the python interpreters enters an error.

It's going to kick out of the program and say hey you have an error and it's going to completely ignore

what's underneath it here we don't have anything but in a real life program we want to avoid these errors

because it stops execution.

So another good way to access a key and to see if it even exists is to use dot get and guess what does

get is did you guess a method.

Well there you go.

Dog get is a method on the object or the dictionary in Python.

So here if we do get age and do run I get none.

So my program doesn't error.

It just says hey there is nothing there.

It's an absence of value.

And we've learned what none means by now.

So that's a really nice way to avoid those errors by the way.

If let's say there's no age in the user but you want to have a default value.

You can do something like this.

So you add a comma and then here you say whatever you want as the default value so let's forget that.

If I click Run I get 55.

Because now I'm saying Hey grab the h from the user dictionary if age doesn't exist on the user dictionary

use 55.

So now we have 55 but if the user already has age and I click Run I get 20.

So this is Hey in case age doesn't exist at a default value that's really really nice.

Now I'm going to show you another way to create a dictionary which is not very common in most of the

time you want to use this syntax but just so you're aware of it.

Here's another way.

Let's say we have a new user so User 2.

I can create here a dictionary by saying dict which again is a built in function.

And in here look at that.

It shows me Hey this is going to create a new empty dictionary and we can create different values key

variable value pairs and we simply say I want the key to equal the value.

So in my case let's just say that I want the name to equal

if I now print out user to well before I click Run I see that I have a red underline and by the way

if you see here pi flakes.

That's something called linking something we'll talk about when we talk about developer environments.

We're using this Lintner that tells you whenever you make errors in Python and it says keywords can

be an expression that just means that hey the keyword needs to be well just a variable that we create.

So if I click Run here look at that I have name John John so we've create a user with this key value

pair.

Now like I said this way of creating dictionaries is not very common.

Most of the time you'll do something like this but at least now you know that this is why this built

in function exists I'll see in the next one.

By.

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