What's an elegant way to test for list index existing?

Chris Green cl at isbd.net
Sun Sep 30 06:13:34 EDT 2018


Glen D souza <glenpop54 at gmail.com> wrote:
> i have a approach, it may not be best
> 
> fld = [ ]
> for data in shlex.split(ln):
>        fld.append(data)
> 
It's certainly simple!  :-)

I (OP) have actually done something quite similar:-

    fld = shlex.split(ln)
    fld.append(999)
    fld.append(999)

It means I can test for '999' as when read from ln they are text
fields and it's text I have created so (unless I get *very* confused)
it will never be 999.

-- 
Chris Green
·



More information about the Python-list mailing list