We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
to understand this you need to understand nested list
if we print nested list this will look something like this
[[1,2][3,4][5,6]]
nested_list[0]
this will choose first element from compex list :
[[1,2][3,4][5,6]] -----> nested_list[0] = [1,2]
and nested_list [0][1]
will look like this
[[1,2][3,4][5,6]] ---- > nested_list[0] = [1,2] and nested_list[0][1] ----> [1,2] , nested_list[0][1] = 2
to select number 2 from first list with index[0]
question No 2:
nested_list.sort(key=lambdax:x[0])
sort() is a function that mean to sort and if it is simple as .sort() that will sort the list from smallest to the biggest for example [2,1,6,2,3].sort() ----> [1,2,2,3,6] and function :
key=lambda x: x[index] : key is command that means
Nested Lists
You are viewing a single comment's thread. Return to all comments →
Ok question No 1:
to understand this you need to understand nested list if we print nested list this will look something like this [[1,2][3,4][5,6]] nested_list[0] this will choose first element from compex list : [[1,2][3,4][5,6]] -----> nested_list[0] = [1,2] and nested_list [0][1] will look like this [[1,2][3,4][5,6]] ---- > nested_list[0] = [1,2] and nested_list[0][1] ----> [1,2] , nested_list[0][1] = 2
to select number 2 from first list with index[0]
question No 2:
sort() is a function that mean to sort and if it is simple as .sort() that will sort the list from smallest to the biggest for example [2,1,6,2,3].sort() ----> [1,2,2,3,6] and function :
key=lambda x: x[index] : key is command that means
sort(key=) ----> sort (in this way= )
lambda in this case is a function to select every element from list , you also can read lambda function here http://www.python-course.eu/lambda.phpa
lambda x: x[1] in this case x is a list [[elements from here][elements from here][elements from here]]
[[1,2,3][4,5,6][7,5,3,2,1]]