tuple to string?
John Machin
sjmachin at lexicon.net
Sun Jul 24 07:18:28 EDT 2005
Steven D'Aprano wrote:
> On Sat, 23 Jul 2005 23:26:19 +1000, John Machin wrote:
>
>
>>Steven D'Aprano wrote:
>>
>>
>>>
>>>>>>''.join(map(lambda n: chr(n), (0x73, 0x70, 0x61, 0x6D)))
>>>
>>>'spam'
>>
>>Why the verbal diarrhoea?
>
>
> One line is hardly verbal diarrhoea.
>
>
>>What's wrong with the (already posted)
>>
>>''.join(map(chr, (0x73, 0x70, 0x61, 0x6D)))
>>
>>???
>
>
> Nothing.
>
> If I had seen the already posted solution using chr on its own without
> lambda, I wouldn't have bothered posting the lambda solution. But I
> didn't, so I did.
>
> As another poster has already pointed out, lambda cries out for over-use,
> and this was a perfect example of it.
Here are a couple of reductions you can use in future, in the order given:
(1)
lambda <args>: foo(<args>) -> foo # for *any* function foo, not just chr
(2)
lambda <args>: <almost_any_guff>
->
def meaningful_func_name(<args>):
<almost_any_guff>
More information about the Python-list
mailing list