[Tutor] Tutor Digest, Vol 103, Issue 82

Aaron Pilgrim aaronpil at gmail.com
Mon Sep 17 23:24:46 CEST 2012


> Message: 7
> Date: Mon, 17 Sep 2012 21:34:05 +0530
> From: Santosh Kumar <sntshkmr60 at gmail.com>
> To: tutor <tutor at python.org>
> Subject: [Tutor] Trying to get next item from a list
> Message-ID:
>         <CAE7MaQZ6XO_YHc4gTF16mMVxn2dAF+ZSAoUpGft21d2G-Q52Hg at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> 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?
>
>
> ------------------------------

Hello, I am new to python.
Here is what I wrote.
my lower() function does not work and it can not take capital letters.

def func3():
	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: ")
	i.strip().lower()
	current = alphabets.index(i)
	print("current index value: ", current)
	next = (current + 1) % 26
	print("next index value: ", next)
	print("The next letter is...", alphabets[next])


More information about the Tutor mailing list