Can someone explain the logic here?

Screen Link:

My Code:
for app in android:
name = app[0]
if name == ‘Instagram’:

Why do we loop by app? app is supposed to be a column so how do we loop using it?
and also what does app[0] actually mean?

Hi @muhammedkorain

Welcome to the community.

So here app is simply a variable name we have given. It can be i, x, or anything_you_want.

The idea of using the variable app is for better readability. We are dealing with the android data set in this case. So each of the rows in this dataset represents the app data. Hence it was given the name app.

You can see, each row comprises of a list. So we are iterating through these lists. The variable app represents these lists.

That also gives hint to your next question.

Since app represents each row in android dataset. So app[0] will represent the first column which is the column that has the names of the apps. It will return ‘Instagram’ in the first case.

If you understand that the iteration happens row by row in the dataset, things will be clearer. This is because you are dealing with lists of list.


Thanks alot Jithins! Much appreciated

1 Like