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.
If all the elems in the heights list are the same (i.e. all the stacks are the same height) then when we convert it to a set it will have only one elem. It's a neat way of checking that all the elems in a list are the same.
Edit:
An equivalent piece of code is:
whilenotall(h==heights[0]forhinheights):
This is less elegant looking but more efficient since it only checks the elems until it finds one which isn't equal to the first.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
If all the elems in the heights list are the same (i.e. all the stacks are the same height) then when we convert it to a set it will have only one elem. It's a neat way of checking that all the elems in a list are the same.
Edit:
An equivalent piece of code is:
This is less elegant looking but more efficient since it only checks the elems until it finds one which isn't equal to the first.