0

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>]

0

1 Answer 1

3

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()]
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks , the second syntax without lambda works! However the first syntax with lambda throws an error like; TypeError: <lambda>() takes exactly 1 argument (0 given)
@Thirai I had forgotten to pass the i in the first one but it should be fixed now. You shouldn't use it anyway -- hence why I'm not used to writing it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.