Phoenix Hudson
Phoenix Hudson

Reputation: 1

How to debug the error "X is unsubscriptable"?

I am trying to create a list of the letters in the alphabet and check a user input to see if each character is in the list associated. However, when I try to go through the list to find if the character is in it, it returns with a "Type Error: Value "ASCIIUPPER.index" is unsubscriptable" or Type Error: Value "ASCIILOWER.index" is unsubscriptable.

Here's where I create the list:

    import string
    ASCIIUPPER = list(string.ascii_uppercase)
    ASCIILOWER = list(string.ascii_uppercase)

and here is where I try to check input:

    for count in range(len(userInput1)):
        loc1 = userInput.index[count]
        if loc1 in ASCIIUPPER:
            for count1 in range(26):
                loc2 = ASCIIUPPER.index[count1]
                if loc1 == loc2:
                    finalInput += loc1
                print(finalInput)

This is only the first part to the conversion.

Upvotes: 0

Views: 120

Answers (1)

skmth
skmth

Reputation: 174

You are using list.index incorrectly. ASCIIUPPER is a list right and to get the index of an item in the list use list.index().

ASCIIUPPER.index('A') will return 0.

I'm not sure what you are trying to do with the multiple for loops.

If all you want to do is check if user input is a letter isn't this sufficient

for loc1 in userInput1:
    if (loc1 in ASCIIUPPER) or (loc1 in ASCIILOWER):
        print loc1

Upvotes: 1

Related Questions