8. and seek! question


#1



https://www.codecademy.com/en/courses/python-beginner-en-4XuFm/0/8?curriculum_id=4f89dab3d788890003000096

so, for personal reasons i had to put this course in stand by, now i have returned and i started to rewatch from the beginning, to make sure i'm understanding everything

there's a thing in this problem that i quite dont get it, here:
def random_row(board):
return randint(0, len(board) - 1)

def random_col(board):
return randint(0, len(board[0]) - 1)

i dont get that len(board[0]), on the previous exercise that wasnt there, i try to understand it by myself but i just dont see it

on the line return randint(0, len(board) - 1) i see that it returns a random number for the row (the "row" as i see it is one of the lists that was created, now, that code selects one of the lists that is within the bigger list that is board), and the len(board) is for any given length.

now, the len(board[0]) i still dont get it, as i see it is just giving me the length of the very first list(or "row" in this case) in board, i dont get how that defines the column

Thanks for any help!



#3

what?, what does this means? :open_mouth:


#4

someone answered but i can't see the answer, why?


#5

the answer to your question is ... it took me long time to understand as well!
len function works on everything that make step+ step + step
so len of string is
Len("game") is step G + step a + step m + step e = 4 steps
len(game[0] = G

len(board) - since board was appended * 5 so its Len/ counting the arrays which means

step 1 0 0 0 0 0
step 2 0 0 0 0 0
step 3 0 0 0 0 0
step 4 0 0 0 0 0
step 5 0 0 0 0 0
len(board[0]) so it goes always to first step of the len which is first line out of 5
so if you put 3 in the column/ len(board[0]-1)
its the first line and since its - 1 so its 4-1

1 O O X O O


#6

ohhh ok i got it now
basically the first len() tells me what row is selected
and then len(board[0]) acts as if its the top of the column, and then you select an element of
board[0]


#7

yes exactly ...
you got it right !


#8

awesome!!!
is nice when you understand!


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.