Python Forum
TypeError: string indices must be integers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: string indices must be integers
#1
Error:
TypeError: string indices must be integers
What does this error mean?

I thought I would've fixed... by adding this
int(numbers[color])
in
while count <= 11:
        for color, value in band_values.items():
                if band_values[color] == int(numbers[color]):
                    return numbers
but didn't work & brought up the same error Cry

I'm new to using a dictionary. I'm trying to use one to help me convert the band values to numeric values by searching through a list.

#The first parameter is the two character string return earlier (numbers)
#This function will convert the two characters to a number value &
#return it.
def calculate_raw_value(numbers):

    count = 0

    band_values = {'K':'0', 'N':'1', 'R':'2', 'O':3'', 'Y':4,'G':5,
                   'L':6,'V':7, 'Z':8, 'W':9,
                   }
    

    while count <= 11:
        for color, value in band_values.items():
                if band_values[color] == numbers[color]:
                    return numbers

                elif count <= 9:
                    count = count + 1
                    continue

                elif count == 10:
                    print("ERROR")

Any extra advice/tips would be appreciated.
Reply


Messages In This Thread
TypeError: string indices must be integers - by thecoziest - Sep-26-2019, 02:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: string indices must be integers, not str hanieh 4 98,417 Jan-04-2021, 05:13 AM
Last Post: delonbest
  please Help. TypeError: list indices must be integers, not str skamaaa01 1 4,396 Feb-04-2018, 12:33 PM
Last Post: Gribouillis
  create a 20 digit string, and cast to a list then add all the digits as integers nikhilkumar 2 6,388 Jul-19-2017, 04:53 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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