All language subtitles for 31. Common List Patterns

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.

Let's talk about some useful tricks with lists that you'll see a lot in Python code.

Well one we have already seen it's this idea of length.

You're going to be using this a lot that is to figure out the length of a list which in our case is

now seven.

Another really useful trick is to reverse a list.

Now I've already showed you how to reverse a list but sometimes you can do that with list slicing against

something that we've seen in String slicing.

So I can actually do basket and then semicolon semicolon negative one if I click run here.

Is that what you expected let's go through this line by line I've sorted the basket so that it's from

a all the way to Z and then I've reversed this.

So it's an Z all the way to a.

And then I've reversed the basket again so that instead of being in reverse it's now in order.

ABC D E X and this list slicing creates a new list right.

If I print basket here you'll see that the basket is the reversed version.

The last action that we've taken on it versus list slicing that creates a new version.

So this notation you'll see a lot with lists when you need to reverse the list.

Or maybe you need to make a copy of the list like this or maybe you need a portion of the list.

Another useful thing that you'll see a lot of is something called range let's comment this out for now.

If I wanted to generate a list really quickly let's say from 1 to 100 I can do something like this.

I can say range and then start and then stop.

So let's do a hundred and if I print this

and I run I get a range 1 to 100 but if I wrap this in a list which is going to create a new list for

us and I click Run look at that I get a range from 1 all the way to ninety nine.

Remember it's the start and then whatever to stop it.

So before it hits 100 it's going to stop.

Now if I remove this and just do one single thing I get a list starting from zero all the way to ninety

nine.

If I want a list that has a hundred and one items because it starts at zero I would just do one hundred

and one end range is something we'll talk about a lot more especially when we talk about loops in programming

but this is a great way of you to generate a list really really quickly especially a numbered list.

Finally the last common thing that you'll see a lot is this idea of DOT join what is dot join join is

actually something that works on strings it's a string method but it's often used this way.

We have an empty string and this empty string.

Let's say sentence and then we can do a sentence.

Dot join and join takes what we call an automobile which is a list for now.

And in here we can have a sentence like high My name is

and now if I print sentence and I click run here.

Hmm.

I don't get anything.

Let's figure out why.

What if I type in an exclamation mark here and I click Run All right.

It's printing out sentence but it looks like Doug join creates a new item for us.

So let's just sign that to the new sentence.

Now if I do new sentence and print that out

we see that I get Hi my name is Jo Jo.

So this is a little funky right.

We have these exclamation marks between our items and join joins these little interval items.

These lists by whatever is in front of it.

So if we actually change this to an empty string click Run we now get this.

If I add a space in between and click Run we get.

Hi my name is Jojo and sometimes you'll notice this pattern a lot especially if you want to join and

create a new string out of a list of items.

Now a shorthand way of doing this is to actually not even bother with this and just doing an empty string

dot joint and then joining all the list items.

There we go.

So all we're doing is combining lists into a strength.

And this is a common pattern that you'll see a lot of 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.