Python Forum
List Indices Must Be Integers, Not Str.
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List Indices Must Be Integers, Not Str.
#2
Run it this way -- see the value of print statements

def fizz_count(x):
   count = 0
   print(x)
   for y in x:
       print(y)
       if x[y] == "fizz":
           count = count + 1
   print count

GroceryItems = ["fizz","soda", "apple", "fizz", "fizz"]

fizz_count(GroceryItems)
Reply


Messages In This Thread
RE: List Indices Must Be Integers, Not Str. - by Larz60+ - Apr-18-2017, 12:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: string indices must be integers deneme2 2 829 Feb-14-2025, 12:23 AM
Last Post: deneme2
  TypeError: string indices must be integers, not 'str' LEMA 2 2,956 Jun-12-2024, 09:32 PM
Last Post: LEMA
  tuple indices must be integers or slices, not str cybertooth 16 20,342 Nov-02-2023, 01:20 PM
Last Post: brewer32
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 2,820 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  boto3 - Error - TypeError: string indices must be integers kpatil 7 3,457 Jun-09-2023, 06:56 PM
Last Post: kpatil
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 9,532 Mar-24-2023, 08:34 AM
Last Post: fullytotal
Question How to append integers from file to list? Milan 8 3,208 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 6,869 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  Error "list indices must be integers or slices, not str" dee 2 3,026 Dec-30-2022, 05:38 PM
Last Post: dee
  TypeError: string indices must be integers JonWayn 12 6,332 Aug-31-2022, 03:29 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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