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.
The "if len(args > 1:" isn't necessary. The input lines never have more than the right number of arguments. It's a HackerRank thing - the input is always reliable unless they explicitly say it might not be.
I once suggested that, where they start with N where N is the number of lines of input, they put more than N lines in the input file and catch out people who ignore N and just read all the lines. They told me that the N is there purely to help people using languages like C that don't have foreach-style loops. They don't see the point in trying to catch people out over basic input structure.
To be fair, I always pay attention to the N lines/words thing no matter the language I'm using for a challenge.
Personally, when I'd use a for loop rather than a comprehension because you're not returning any values when executing the methods; it's a purely side-effecting loop. But if you want to use a comprehension, use a generator comprehension - parentheses rather than square brackets. As it is, you're building a list and then throwing it away.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Set .discard(), .remove() & .pop()
You are viewing a single comment's thread. Return to all comments →
The "if len(args > 1:" isn't necessary. The input lines never have more than the right number of arguments. It's a HackerRank thing - the input is always reliable unless they explicitly say it might not be.
I once suggested that, where they start with N where N is the number of lines of input, they put more than N lines in the input file and catch out people who ignore N and just read all the lines. They told me that the N is there purely to help people using languages like C that don't have foreach-style loops. They don't see the point in trying to catch people out over basic input structure.
To be fair, I always pay attention to the N lines/words thing no matter the language I'm using for a challenge.
Personally, when I'd use a for loop rather than a comprehension because you're not returning any values when executing the methods; it's a purely side-effecting loop. But if you want to use a comprehension, use a generator comprehension - parentheses rather than square brackets. As it is, you're building a list and then throwing it away.