Skip to main content

Command Palette

Search for a command to run...

Why I Was Wrong About Lambda Functions: Week 1 of My ML Internship

Updated
3 min read
Why I Was Wrong About Lambda Functions: Week 1 of My ML Internship

Week one of my Machine Learning internship with DataraFlow quickly concluded and it was nothing short of amazing. From the onboarding session to the course materials, it is evident that careful attention was paid to every detail of this program.

This week we went back to the basics of Python programming! We learnt about data types, data structures (I know I said basics, 😅), Loops (for and while loops) and a whole lot. Personally, most of these concepts are not new to me but this refresher opened up my understanding of some of those concepts. Prior to this, I had a few weak areas that I was able to address during this week’s module.

First amongst them is the lambda expression. A lambda expression is a concise, anonymous function defined inline, without a formal name, that is primarily used for short, single-statement operations where defining a full function would be unnecessarily verbose. It allows you to create a function on the fly and pass it directly as an argument to higher-order functions, like those for sorting, filtering, or mapping data, thereby enabling a more functional programming style. By keeping the logic right where it is used, lambdas can significantly improve code readability for simple tasks, although they are intentionally limited to a single expression and are not suited for complex multi-step procedures.

Prior, I believed that lambda expressions were fundamentally different from and more powerful than regular named functions defined using def function. However, in reality, they are simply a syntactic shortcut for creating simple, anonymous function objects, just without a name and with more limited structure. Their true purpose is conciseness and inline use, not performance or unique capability, and overusing them for complex logic actually harms readability rather than improving it.

Another concept that clicked for me in a new way was the true nature of Methods. At their core, methods are actions. They are the "verbs" that define what an object can do or what can be done to an object. While attributes (like object.color or object.size) describe the object's current state, methods (like object.save(), user.authenticate(), or list.sort()) describe its behavior. What they actually do is manipulate or interact with the object's internal data. When you call file.save(), the save method takes the file's internal data (its content, name, location) and writes it to a disk. When you call list.sort(), the sort method rearranges the list's internal items into a new order. The method contains the step-by-step instructions for performing a specific task related to the object, often changing the object's state or providing information based on it. In essence, a method bundles a set of instructions together and gives it a name, allowing you to perform complex operations on an object through a simple, reusable command.

Week 1 came, and we truly hit the ground running, I’m really hopeful for what this journey holds and I believe I’ll come out of it a lot better than I am now.

DataraFlow Internship

Part 1 of 1

In this series, I’ll be sharing weekly updates from my journey as an ML intern at Datara Flow. I’m documenting to track my own growth and also to encourage others who might be on a similar path. Here’s to the little drops that make up the ocean🥂