[Tutor] Trying to get next item from a list

Sarma Tangirala tvssarma.omega9 at gmail.com
Mon Sep 17 18:18:06 CEST 2012


On 17 September 2012 12:04, Santosh Kumar <sntshkmr60 at gmail.com> wrote:

> Here is the script:
>
> alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
> 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
> 'z']
> i = input("Press any English alphabet: ")
> current = alphabets.index(i)
> print(current)
> next = current+1
> print(next)
> print(alphabets.index(next))
>
> I am getting a ValueError.
>
> And as you can see, I just trying to get the next item. So is there
> any way I can get same functionality in less line of codes?
>
> <SNIP>
When you access index the second time you are trying to do so with the
value of the index.

-- 
0 1 0
0 0 1
1 1 1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120917/fde7d342/attachment.html>


More information about the Tutor mailing list