Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1
Hey, hello! Let's look at dictionaries in
this lecture. This far we've looked at strings
3
we've looked at lists and tuples and now we
have yet another data type and these are
5
dictionaries. Let me open the python shell.
And let me create a list first I'm just
7
creating this for reference, so to
compare lists with dictionaries, but you
9
don't need to create a list for creating
a dictionary. So to create a dictionary
11
you need curly brackets, so open and
closing curly brackets and then inside
13
that you'd pass the items of the dictionary.
Now the difference here with
15
dictionaries is that instead of letting
Python add default indexes for your
17
items you want to create those indexes
yourself exclusively so therefore for
19
dictionaries you do something like this.
Name, a column and then the item. Let me
21
write another one, surname column and
then the other item and yeah that's it.
23
That's the dictionary. So what we have
here is when I was talking about
25
indexing I was referring to these things.
Actually these two are referred to as
27
keys, not indexes so for dictionaries you
can create custom indexes so to say and
29
so these are keys so we have key and
value, key and value. This is good because
31
now if you want to access one of the
values of the dictionary again you'd use
33
square brackets just as you did with
strings lists and tuples and then there you
35
pass the key which value you want to
extract, so if you want to extract John,
37
you want to pass the key of John and
that will extract the John value. Something
39
to note is that dictionaries are
an unordered colecton
41
of items and so sometimes you may
notice that the order of the key and
43
values is not maintained so you may see
that surname has gone to the first place, so
45
surname Smith and the pair has gone the
first one and name John is the second
47
one and so on. So this is different from
lists, strings and tuples. The reason why
49
Python doesn't keep the order is that
you know the way you access dictionaries
51
is you exclusively pass the key of the
dictionary when you access it and so you
53
don't need to know the order of the dictionary.
And whenever you want to access
55
something you say the surname for
instance and that will the return Smith
57
no matter where Smith is, so whether it
is the first one, the second one or over
59
and so on. And interestingly in
dictionaries you can also pass, you can
61
have like lists as values or even tuples,
so let me write a circle there or let me
63
keep it like that and let me add another
key and pair here. Let's say cities. Let's say
65
Joe Smith lives in three cities, Porto
and San Diego and Bali. You close
67
bracket there so as you see we have the
key here, we have a column and then you
69
have the value which can be anything so
it can be string, it can be a number, it
71
can be at list, a tuple. In this case
that's a tuple so if you access now
73
cities like that, you'd getโฆ Sorry, I'll add
two bracket there, so you'd get the tuple.
75
And then you can also do tricks like you
know if you want to access Bali you'd
77
have other brackets there and pass 2.
And that would return Bali, so why is that?
79
That's because you know up to here you
have a tuple,
81
but that's a triple object and
then from that tuple you use again the
83
square brackets notation to access an
item from that tuple, so you want item
85
with index two and that is Bali and yeah
that's about dictionaries. Try them out
87
some more, play around and you will be able
to comfortably create and access items
89
from a dictionary. So I hope you enjoyed
this and talk to you later.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.