"adam carr" <[EMAIL PROTECTED]> writes:

> Denis kindly provided the following code which does this well:
>
> def mkiter( x ):
>    """ list -> list, el -> [el], None -> []
>        usage: for x in mkiter( func returning list or
> singleton ): ...
>    """
>    return (x if hasattr( x, "__iter__" )  # list tuple ...
>        else [] if x is None
>        else [x]
>        )
>
> # test --
> print mkiter( 1 )
> print mkiter( (2,3) )
> print mkiter( None )

If you want to go this way, then why not write it simply:

def mkiter(x):
    if hasattr(x, '__iter__'):
         return x
    return [] if x is None else [x]

-- 
Arnaud

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to