Nice way to cast a homogeneous tuple

wheres pythonmonks wherespythonmonks at gmail.com
Wed Jul 28 09:35:52 EDT 2010


Thanks ... I thought int was a type-cast (like in C++) so I assumed I
couldn't reference it.



On Wed, Jul 28, 2010 at 9:31 AM, Nick Raptis <airscorp at otenet.gr> wrote:
> Ep, that missing line should be:
>
> On 07/28/2010 04:27 PM, Nick Raptis wrote:
>>
>> On 07/28/2010 04:15 PM, wheres pythonmonks wrote:
>>>
>>> f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456')))
>>> 102
>>>
>>> But this seems too complicated.
>>>
>>>
>> Well, you don't need the lambda at all
>> int   ===    lambda x: int(x)
>>
>> So just write
>>
> f( *map(int, struct.unpack('2s2s2s', '123456')))
>
> Pretty compact now, isn't it?
>
>> It's like writing:
>> def myint(x):
>>    return int(x)
>>
>>
>> Nick,
>>
>> Warm thanks to Steven D' Aprano who taught me that just yesterday in the
>> Tutor list ;)
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list