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 = [
"S-#--",
"-#---",
"-#-#-",
"---#X"
]
maze2 = [
"S----",
"-#--#",
"---#-",
"-#-#X"
]

--

--