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.
Awesome solution, but you don't really need to sum list.
It is enough to sum generator expression which may be defined with no parentheses in this context:
print sum( (i in A) - (i in B) for i in sc_ar )
(don't mind whitespaces inside of sum() )
It leads to little economy of time because we don't waste it on creating list and storing it at some temporary place and only then summing elements of it.
Instead, we calculate each element on-the-fly, only when we need it
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
No Idea!
You are viewing a single comment's thread. Return to all comments →
Awesome solution, but you don't really need to sum list.
It is enough to sum generator expression which may be defined with no parentheses in this context:
print sum( (i in A) - (i in B) for i in sc_ar ) (don't mind whitespaces inside of sum() )
It leads to little economy of time because we don't waste it on creating list and storing it at some temporary place and only then summing elements of it.
Instead, we calculate each element on-the-fly, only when we need it