Python Forum
string indices must be integers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string indices must be integers
#5
data is the dictionary. When you do for element in data, element takes on the value of the key, first iteration, it is 'sentence', second iteration, it is 'tags' Get rid of the for loop and it will work.
import json
data = json.loads('{"sentence": ["what", "is", "a", "transistor"],"tags": ["WH", "AUX", "DT", "NN"]}')
print(type(data))
print(data["sentence"])
 
sents = []
tags = []
 

sents.append(data['sentence'])
tags.append(data['tags'])
Reply


Messages In This Thread
string indices must be integers - by constantin01 - Apr-22-2020, 09:01 AM
RE: string indices must be integers - by buran - Apr-22-2020, 09:10 AM
RE: string indices must be integers - by buran - Apr-22-2020, 10:00 AM
RE: string indices must be integers - by TomToad - Apr-22-2020, 10:13 AM
RE: string indices must be integers - by buran - Apr-22-2020, 10:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: string indices must be integers deneme2 2 776 Feb-14-2025, 12:23 AM
Last Post: deneme2
  TypeError: string indices must be integers, not 'str' LEMA 2 2,847 Jun-12-2024, 09:32 PM
Last Post: LEMA
  tuple indices must be integers or slices, not str cybertooth 16 20,091 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,763 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  boto3 - Error - TypeError: string indices must be integers kpatil 7 3,374 Jun-09-2023, 06:56 PM
Last Post: kpatil
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 9,434 Mar-24-2023, 08:34 AM
Last Post: fullytotal
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 6,709 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  Error "list indices must be integers or slices, not str" dee 2 3,000 Dec-30-2022, 05:38 PM
Last Post: dee
  TypeError: string indices must be integers JonWayn 12 6,174 Aug-31-2022, 03:29 PM
Last Post: deanhystad
  TypeError: list indices must be integers or slices, not range Anldra12 2 4,659 Apr-22-2022, 10:56 AM
Last Post: Anldra12

Forum Jump:

User Panel Messages

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