Set .discard(), .remove() & .pop()

  • + 1 comment

    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.