Searching a list or an Array in Python смотреть онлайн
This teaches how to search an array or a list in Python.
I start with the list my list is equal to so i'm going to put some values in my
list so if i look for if i put 2 5 7
5 three
eight nine okay so
now what i'm going to do here is i'm
going to write a program
that will search for a number in the
list
and it will return if it's in the list
or not
so what i'm going to do is first of all
i'm going to start by saying
number equals to hint
input and i'm gonna say
type the number
you are searching
okay so now from here
we're gonna use a for loop because a for
loop is in is
is necessary so that i can go through
every single
items in the list okay
and go through every single item in the
list to check
if the number that i type is actually in
the list or not
so i'm gonna use this i'm gonna say for
i
in my list
or i in my list
i will say print
i'll say print i
okay so now
let's just run this okay so to run this
i'm going to say program
one there you go
and i'm gonna run that okay so i need
saving this first
okay
okay if i run this it says type a number
you want okay if i type four
right okay what's happened there if i
type four
it's basically printing all the item but
that's not what i want
okay it's printed and it say two five
seven five
now what i'm going to do is i'm going to
change that to something different
okay i'll make sure that all the numbers
i have is different
so if i run this what it's currently
doing is it's giving me
it's printing even if i put six whatever
i put
it's not giving me much all it's doing
is it's printing
all the items in my list right now so
from here i'm gonna do this
i will say if
okay before it prints i'm gonna say if
the
number that i'm typing is
equal to equal to i
okay i is are the numbers money so if
you see when i print i i means all these
items
if the number i'm typing is the same
as i then i'm gonna say print
i'm gonna say number
found
and i'm gonna put the number found which
is obviously the i
okay um okay so let's run that now
so if i type if i'm looking for the
number seven
there you go you could see staying two
five seven
there we go number found six three eight
nine
so it's definitely finding it it's
finding it it's checking if the number
is comparing
it's telling me if it's there or not now
from here
how can i make it better i can use break
break what will break do it will stop as
soon as it finds the number
so if i look for the number
six this time there you go it will go
through
each of the numbers two five seven six
number found six
so what i need to do here is instead of
printing the eye
i can remove that and just comment that
there we go if i run this now if i say
number six
straight away he doesn't print the
numbers he goes straight into finding it
and it stops okay so the break
is interesting and he does that now i
can expand on this
i can say else
else print
number not found so what does that do if
i'm looking for a number
if i say 15 or 17
it will say number not found not found
not found out basically is going through
every single one of them and it's
telling you it's not found
now if i remove this else
what would happen if i remove this else
what would happen so if i search for a
number which is not in my list 17
it will run and say it won't even tell
me anything
it means that it's not there okay so
here
this is a good way of having it to say
if you want to say
it's not found but this one is more than
enough
to tell you that the number is not there
now
if i want to run it only once
instead of running multiple times what i
can do is
i can format
uncomment i can get it to run
outside the loop like this let's check
that
what difference does it make if i put 17
still running it multiple times because
it's still inside my loop
if i put it outside the list outside my
array
sorry outside my for loop if i look for
17
there you go you only see number not one
because what is done here is
when it's gone through all of this like
you see here the 17
it was checking every single number but
it was telling me it's not time not
found out
the second time when i did 17 it
basically didn't run anything but this
time
what it does is it goes outside the loop
so here i can remove this house
completely i don't need the else at all
so what it does is it runs through all
of this if it doesn't find anything
it will print this num this one that
says number no file which is outside
my my folder okay
so this is how you write a program about
searching
from a list
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Searching a list or an Array in Python» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.