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.
Part A defines the element(s) put into the new list. Part B is a set of <"for" element(s) "in" collection> statements. Part C contains optional "if" statements that filter each collection element from consideration. In this case it looks like...
The tricky part is between "for" and "in" of Part B.
B slices the parents child lists horizontaly into two new lists (name and marks), iteratively assigning name=marksheet [0] and marks=marksheet [1]
Part A says "im only interested in keeping the marks list." We throw away the new list called "name."
I suppose if the childlists each had N elements you could say,
"for new1, new2, new3,,,newN in ParentList" and be able to manipulate N new lists in your part A.
Hope helpful
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Nested Lists
You are viewing a single comment's thread. Return to all comments →
"list comprehension" is in the form : [ A B C]
Part A defines the element(s) put into the new list. Part B is a set of <"for" element(s) "in" collection> statements. Part C contains optional "if" statements that filter each collection element from consideration. In this case it looks like...
The tricky part is between "for" and "in" of Part B.
B slices the parents child lists horizontaly into two new lists (name and marks), iteratively assigning name=marksheet [0] and marks=marksheet [1]
Part A says "im only interested in keeping the marks list." We throw away the new list called "name."
I suppose if the childlists each had N elements you could say, "for new1, new2, new3,,,newN in ParentList" and be able to manipulate N new lists in your part A.
Hope helpful