← Back to challenges

Likes vs. Dislikes

PythonHardloopsarraysconditionslogic

Instructions

YouTube currently displays a like and a dislike button, allowing you to express your opinions about particular content. It's set up in such a way that you cannot like and dislike a video at the same time.

There are two other interesting rules to be noted about the interface:

  1. Pressing a button, which is already active, will undo your press.
  2. If you press the like button after pressing the dislike button, the like button overwrites the previous "dislike" state. The same is true for the other way round.

Create a function that takes in a list of button inputs and returns the final state.

Examples

like_or_dislike(["Dislike"]) ➞ "Dislike"

like_or_dislike(["Like", "Like"]) ➞ "Nothing"

like_or_dislike(["Dislike", "Like"]) ➞ "Like"

like_or_dislike(["Like", "Dislike", "Dislike"]) ➞ "Nothing"

Notes

  • If no button is currently active, return "Nothing".
  • If the list is empty, return "Nothing".
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Hold Your Breath!