Thirai
Thirai

Reputation: 1

lambda function returning function name

I have a list where the items are dictionaries. the dictionary values are in unicode format and am trying to compare the unicode values to strings. So, I tried a below lambda function expecting a conversion of unicode to string;

a=[(lambda x: x.unicode('UTF-8') ) for i in paid_submissions[0].values()]

print(a)

[ at 0x11335db18>, at 0x113357d70>, at 0x113357b90>, at 0x113357a28>, at 0x1133b5050>, at 0x1133b50c8>]

Upvotes: 0

Views: 60

Answers (1)

FHTMitchell
FHTMitchell

Reputation: 12156

Because you're just returning the lambda object without calling it on anything. If I understand what you're trying to do correctly, you would need to call the lambda on i like so.

a = [(lambda x: x.unicode('UTF-8'))(i) for i in paid_submissions[0].values()]

But the lambda expression is a waste. This can be more easily (and more efficiently) written as

a = [i.unicode('UTF-8') for i in paid_submissions[0].values()]

Upvotes: 3

Related Questions