0

Look this code:

arg = 'yes'
(lambda x: dict(yes=1, no=0)[x])(arg)

It returns:

1

But I'd like to return arg itself if arg is not 'yes' or 'no'. Something like:

arg = 'maybe'
(lambda x: dict(yes=1, no=0, x=x)[x])(arg)

I'm getting a error here...

Can I do that? How to do that?

marcio
  • 566
  • 7
  • 19
  • Why do you even define a `lambda`? Your whole code is just `dict(yes=1, no=0).get(arg, arg)`. – mkrieger1 Sep 18 '21 at 13:49
  • @mkrieger1, yes, `get` does exactly what I want to do. Ty. But I don't think that is the same question mine. About why lambda, because I want to test applymap method. YET, why down vote everything? – marcio Sep 18 '21 at 14:05

1 Answers1

0

If you want to use lambda try this:

arg = 'maybe'
(lambda x: dict(yes=1, no=0).get(x,x))(arg)
# maybe
I'mahdi
  • 23,382
  • 5
  • 22
  • 30