Implicit lists
Dale Strickland-Clark
dale at riverhall.NOTHANKS.co.uk
Thu Jan 30 09:41:33 EST 2003
In many places, often small utility functions, I find myself using the
form:
lst = maybeAnArg
if type(lst) not in (list, tuple)
lst = [lst]
for x in lst:
whatever
or
lst = maybeAnArg
if type(lst) not in (list, tuple)
lst = [lst]
mangle = [x for x in lst if whatever]
In other words, I want to be able to treat an argument of arbitrary
type as a list of 1 if it isn't already a list.
Has anyone got a neater way of doing this?
Thanks
--
Dale Strickland-Clark
Riverhall Systems Ltd
More information about the Python-list
mailing list