Python - Finding items in a list

Sharing buttons:

finding items in Python lists there's

two ways to find items from the list the

first one is to look for look for the

item but for the item there we go and

this is actually really really easy

Python deals this really well we can say

for instance we just print we just want

to true or false print and let's say

bread in shopping there we go

bread is in shopping so it's printed

true there we go and let's try cheese

and shopping good stuff false so that's

a nice easy way doing it you very rarely

do that unless you just do it from

debugging usually you want to do

something so you've normally use it with

an if statement seeds say for instance

if shop it let's sort of look if bread

in shopping there we go French yes we

have bread there we go so there we go

if bread in shopping there we go yes we

have bread and it's printed yes we have

a bread perfect as breads there and

that's a look if cheese good shopping

yes we have cheese there we go and as

you can see there it's not printed yes

we have cheese because there's no cheese

in there's no cheese in the shopping

there we go yes that's the easy way

looking for an item the other way is to

find what is at a position a list what

is that today that's an index in a list

so for instance here we go

let's say we want to find out what the

second item is in the list that's quite

easy just type in the name of the list

let's just do we use it with a print

shopping open brackets and then we put

the index that we want to look at so for

instance our index as

said before he starts counting at zero

so there's our list 0 1 2 we want to

find out what's in item 2 of the list of

it I know it's jam but let's just find

it out

so item 2 which of course would be index

number 1

then let's print shopping there you go

jump that's it super duper easy