Implicit lists
Dale Strickland-Clark
dale at riverhall.NOTHANKS.co.uk
Thu Jan 30 15:03:25 EST 2003
alloydflanagan at attbi.com (A. Lloyd Flanagan) wrote:
>In python, if you ever try to explicitly check the type of something,
>you're almost certainly doing it wrong. You don't care if the thing
>is a list, usually, you want to know if it's a sequence, whether a
>list, tuple, set, or some user-defined type. So try subscripting it:
>
>def aslist(x):
> try:
> x[0]
> except TypeError:
> return [x]
> return x
>
>or just:
>
>try:
> mangle = [x for x in lst if whatever]
>except TypeError:
> mangle = [x for x in [lst] if whatever]
x[0] takes the first char of a string and iterating over a string
gives you each character.
Not what I'm after, I'm afraid.
--
Dale Strickland-Clark
Riverhall Systems Ltd
More information about the Python-list
mailing list