Can ChatGPT Explain Code?

An analysis of its ability to understand and explain code using Python functions from low to high complexity

Thomas A Dorfer
7 min readJan 18, 2023
Photo by Chris Ried on Unsplash

Since OpenAI launched ChatGPT in November last year, its potential applications have been explored extensively. Within the tech community, there has been a growing interest in evaluating whether ChatGPT can assist with coding or even outperform its human counterparts. Results so far have been mixed, with a seemingly unanimous conclusion: while the tool’s abilities are impressive, it also demonstrates significant limitations.

In this article, we will look at ChatGPT’s ability to understand and explain code. This can be particularly useful for collaborative projects that require project members to be able to read and understand each other’s code in order to effectively debug or contribute to it. Specifically, we will look at Python functions in ascending order of complexity and evaluate ChatGPT’s interpretation of the code.

Note: Complexity here is a subjective evaluation by the author. Therefore, LeetCode tasks have been included to accompany the examples at the corresponding complexity levels provided in this article.

Low Complexity

Example 1

--

--

Thomas A Dorfer
Thomas A Dorfer

Written by Thomas A Dorfer

Data & Applied Scientist @ BCG. I mainly write about data science and technology.

Responses (1)