r/PythonProjects2 • • Oct 22 '25

Python daily with

Post image

🧠 Think you're a Python pro? This sneaky list mutation trick has tripped up even experts – what's the output of nums and result? Drop your pick (A/B/C/D) below and see if you spot the gotcha! 🐍 #PythonQuiz #CodingChallenge

122 Upvotes

37 comments sorted by

View all comments

0

u/[deleted] Oct 24 '25

[deleted]

1

u/eggrattle Oct 25 '25

You should definitely try understand what is happening. It is a common issue that occurs and can have dire consequences.

Lists are mutable, and the append changes the list in memory, which is generally not what is intended when the function is returning a new list.

Concepts to learn, mutable vs immutable, memory references, modify in place rather than copy on modify.