Python Forum
List Indices must be Integers?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List Indices must be Integers?
#1
I'm trying to plot a list of the the outputs as a list with the corresponding time values, for this function with a varied number of iterations. I'm not sure why I keep getting "List Indices must be Integers" however. Was wondering if anyone could look at my code and see what's wrong and how I might fix it.

 

def iterate3(finaltime2,stepsize):
    g(x) = 10*e^(0.05*x)
    count = srange(0,finaltime2/stepsize)
    initialvalat0 = [10]
    for i in count:
        a = g(initialvalat0[i])
        initialvalat0.append(a)
    return zip(srange(0,finaltime2/stepsize),initialvalat0)

graph4 = iterate3(10,0.1)
graph5 = iterate3(100,0.1)
graph6 = iterate3(100,0.01)

list_plot(graph4)
Reply
#2
You need to provide: (1) the stacktrace for your problem and (2) the full code that produces that stacktrace.
Ideally you provide a minimal amount of code for the problem you're having (5-10 lines, rather than your full project), but (1) and (2) are essential to us providing help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tuple indices must be integers or slices, not str cybertooth 16 11,078 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 1,091 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  boto3 - Error - TypeError: string indices must be integers kpatil 7 1,183 Jun-09-2023, 06:56 PM
Last Post: kpatil
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,185 Mar-24-2023, 08:34 AM
Last Post: fullytotal
Question How to append integers from file to list? Milan 8 1,360 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 1,931 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  Error "list indices must be integers or slices, not str" dee 2 1,393 Dec-30-2022, 05:38 PM
Last Post: dee
  TypeError: string indices must be integers JonWayn 12 3,261 Aug-31-2022, 03:29 PM
Last Post: deanhystad
  read a text file, find all integers, append to list oldtrafford 12 3,371 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  TypeError: list indices must be integers or slices, not range Anldra12 2 2,501 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