5 Python Questions 75% Of You Probably Can’t Solve In One Line Of Code

Liu Zuo Lin
4 min readJun 15, 2022
More art from my talented outsourced artist

Being able to write code in one line probably won’t guarantee you a high-paying tech job, but it sure does feel satisfying. Here are thus 5 Python questions that can usually be easily solved under normal circumstances. The catch — you need to solve it in one line of code.

1. Checking If A Number Is Prime

Let’s start with something not too difficult (I hope). A prime number is an integer that

  1. can only be divided by 1 and itself
  2. is larger than 1

Examples of prime numbers:

2 3 5 7 11 13 17 19

Examples of non-prime numbers (as they can be divided by another integer other than 1 or itself)

4 6 8 9 10 12 14 15 16 18 20

Write a function is_prime that takes in a positive integer n, and returns True if the n is a prime number and False otherwise. Do this in ONE line.

2. Checking If Maze Is Solvable

You are given mazes (2D lists) like these:

maze1 = [
maze2 = [
  • The S character represents the starting point of the player.
  • The X character represents the objective
  • - characters represent roads, which the player can walk on
  • # characters represent walls, which the player cannot walk on
  • The player needs to reach the object X from S
  • S will always be at the topmost, leftmost coordinate, but X can be anywhere.
  • The player can only move horizontally and vertically, one step at a go.

Write a function is_solvable(maze) that takes in a maze, and returns True if the maze if solvable and False otherwise. A maze is solvable if it is possible for the player to get to X from S.

Liu Zuo Lin