[Python-Dev] get for lists and tuples?
Raymond Hettinger
rhettinger at ewtllc.com
Tue Jul 11 20:19:48 CEST 2006
Russell E. Owen wrote:
>I'd like to have the get method available for lists and tuples. (I
>figured this must have been discussed before but can't recall it and
>didn't turn anything up on google).
>
>It's obviously not a use-all-the-time method (or it'd already be there),
>but I find myself wanting it often enough to justify it in my own mind
>(and curse this omission, relative to dict).
>
>Basically I run into it when parsing data of variable length (where the
>extra elements have some obvious default value), including config files,
>sys.argv (for simple command scripts), that sort of thing.
>
>
How about:
optarg = argv[4] if len(argv)>4 else 'default'
>Yes a 4-liner does the job, but "get" would be a much clearer way to
>write it.
>
>Anyway, I'm just testing the waters. If it's not heresy then I'd like to
>do what I can to make it happen.
>
>
Perhaps in an alternate universe ;-)
Raymond
More information about the Python-Dev
mailing list