Convert '165.0' to int

Billy Mays 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com
Mon Jul 25 13:11:28 EDT 2011


On 07/25/2011 05:48 AM, Steven D'Aprano wrote:
> But if you're calling a function in both cases:
>
> map(int, data)
> [int(x) for x in data]
>

I am aware the premature optimization is a danger, but its also 
incorrect to ignore potential performance pitfalls.

I would favor a generator expression here, if only because I think its 
easier to read.  In addition, it properly handles large amounts of data 
by not duplicating the list.  For very long input sequences, genexp 
would be the proper thing to do (assuming you don't need to index into 
results, in which case, its wrong.)

I think the fastest way to solve the OP's problem is the following: ;)

def convert_165_0_to_int(arg):
     return 165


--
Bill



More information about the Python-list mailing list