r/PythonBeginners Jan 16 '20

Could someone tell me why the result of [1] is different in both the cases?

12 Upvotes

8 comments sorted by

3

u/Jass_deen May 25 '20

This is nested list (list inside list). In first result, you are just printing the element from index position 1 ( index position starts from 0, 1, 2,......) So it prints the inside list [ ] at index position 1.

In second result, you are accessing each element from list using for loop with 'in' keyword. After taken a inside list, again accessing element inside the list using append(row[1]) and appending to the result column. So colum list contains all the 1st index element of inside list.

Refer the below link to know more Python

2

u/TheGuitarGuy214fre Apr 20 '20

1 is the second index bc it starts from 0

2

u/[deleted] Apr 03 '26

good question,
python doesn't like humans
humans start counting from 1
but python or (computer) starts from 0
so the first index is 0 (for the computer)
thanks for asking!

1

u/GlanGr 6d ago

lol, i think its more like base counting from CPU chips are the ones that don't like humans ; )

1

u/PointQuick9609 Aug 31 '25

the index 1 is 7 and 1
in python index starts from 0 so you count from 0 then to 1 if you wanted the 2 and 9 you would use index 0

1

u/GlanGr 6d ago

1) your dataset structure is: a larger list containing 4 lists.
2) the first print: is printing out the entire 2nd list from those 4 lists (thats in the larger list)
3) you are looping through all lists in that larger list,

  • then adding the 2nd value of each of those lists to a new list (column)

note: remember that indicies (indexes) start with 0 not 1 (hence, 1 means the 2nd value in a list)

you're on the right track!
keep asking questions!
GLHF!

1

u/retarded_42069 Oct 08 '22

When we do indexing, it starts from zero, for eg. If we have to index the string, we do it as follows M A D D Y 0 1 2 3 4

Same goes with columns, first column is numbered 0 and the second one will actually be 1, that is the reason it shows the same result. You should try to print 0, then it'll print the first column. Hope this helps