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.
I don't disagree with the principle but in this specific case there's absolutely nothing wrong with using a list comprehension instead of a for loop. The comprehension is doing a simple job elegantly.
If this were production code, I'd use a generator rather than a comprehension, to avoid loading the entire data set into memory unnecessarily, but that's not a problem with the tiny data set here.
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 →
I don't disagree with the principle but in this specific case there's absolutely nothing wrong with using a list comprehension instead of a for loop. The comprehension is doing a simple job elegantly.
If this were production code, I'd use a generator rather than a comprehension, to avoid loading the entire data set into memory unnecessarily, but that's not a problem with the tiny data set here.