Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyLint W0108: Lambda may not be > necessary (unnecessary-lambda)

pylint is returning the below message for the code that I have below :

data.py:125:30: W0108: Lambda may not be necessary (unnecessary-lambda)

in_p = ', '.join(list(map(lambda x: "'{}'".format(x), data)))

Why is lambda not required here and how can it be refactored?

like image 767
Punter Vicky Avatar asked Jan 24 '26 07:01

Punter Vicky


1 Answers

"'{}'".format is already a function; your lambda expression defines a function that does nothing except take an argument and pass it on to another function. You can simply write

in_p = ', '.join(list(map("'{}'".format, data)))

Some might prefer to use a list comprehension here:

in_p = ', '.join(["'{}'".format(x) for x in data])

It might also be worth using a temporary variable for readability.

quote_it = "'{}'".format
in_p = ', '.join(list(map(quote_it, data)))
# in_p = ', '.join([quote_it(x) for x in data])
like image 150
chepner Avatar answered Jan 25 '26 21:01

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!