[Tutor] changing list index start

Rance Hall ranceh at gmail.com
Sat Sep 11 15:25:12 CEST 2010

On Fri, Sep 10, 2010 at 6:14 PM, Lie Ryan <lie.1296 at gmail.com> wrote:
> On 09/11/10 07:36, Rance Hall wrote:


> In most cases in Python, you would almost never need to reference the
> list's index directly since python makes it easy to use iterators;
> however in your particular case, which is a valid exception, enumerate()
> takes an optional second argument `start` which defines the number that
> enumerate start to count with, i.e. you can do:
> for i, option in enumerate(mainmenuoptions, 1):
>    print('%s. %s' % (i, option))
>> php provided a way to change this, but I can find no documentation
>> that says python can do this as well.

Thanks everyone for responding,  Because this menu structure is
repeated many times in my code, the ideal solution would have been to
"set index start = 1" in the beginning of the script.

something like sysctl variables in Linux perhaps but in this case only
valid for this program.

Its clear from the responses that this solution is not available in
python, I wish it were, it would make my life much easier for this

I like the approach that Lie suggested, as it seems more "natural
python" to me as opposed to a workaround.

However this is also only half a solution since it applies to the
printed menus only and not to the response afterward.

It seems that Luke is right looks like we have to do math with the indexes.

Lie also referred to my particular case as a valid exception, are
there enough other such valid exceptions that requesting a feature
enhancement would gain some traction?

If this is but one of a few special cases, I doubt it would be worth
the time or trouble to formally make the request.

Maybe I should ask if there is a better way to do what I want to do
here. Is there?

More information about the Tutor mailing list