Python Forum
Variable for the value element in the index function??
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable for the value element in the index function??
#2
This is 'long hand' and could be shorter.

alpha_upper = [chr(n) for n in range(65, 91)]  # A...Z
alpha_lower = [chr(n) for n in range(97, 123)]  # a...z

alpha_lst = alpha_lower + alpha_upper
alpha_lst.sort()
alpha_input = ""
while alpha_input not in alpha_lst:
    alpha_input = input("Enter a letter of the English alphabet: ")

index_num = alpha_lst.index(alpha_input)
char = alpha_lst[index_num]
print(index_num, char)
I think it's what you're trying to do.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Messages In This Thread
RE: Variable for the value element in the index function?? - by rob101 - Jan-20-2024, 01:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 763 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,671 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 1,197 Aug-07-2023, 05:58 PM
Last Post: Karp
  Index Function not recognized in Python 3 Peter_B_23 1 1,512 Jan-08-2023, 04:52 AM
Last Post: deanhystad
  Retrieve variable from function labgoggles 2 1,153 Jul-01-2022, 07:23 PM
Last Post: labgoggles
  Cant transfer a variable onto another function KEIKAS 5 2,063 Feb-09-2022, 10:17 PM
Last Post: deanhystad
  myList.insert(index, element) question ChrisF 1 1,751 Aug-27-2021, 03:49 PM
Last Post: bowlofred
  How i can add elements to table index of element blazej2533 3 2,151 Dec-03-2020, 08:16 PM
Last Post: Larz60+
Question Matching variable to a list index Gilush 17 6,322 Nov-30-2020, 01:06 AM
Last Post: Larz60+
  How to get index of minimum element between 3 & 8 in list Mekala 2 2,662 Nov-10-2020, 12:56 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020