When I try to run this I get this error TypeError: list indices must be integers or slices, not list

Related searches
HomeworkList = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
WeekDays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
PersonNames = ["Jack", "Mary", "John"]

for people in range(len(PersonNames)):
    for day in range(len(WeekDays)):
        HomeworkList[PersonNames][WeekDays] = int(input("Total minutes for %s, on %s \n>" % (PersonNames[people], WeekDays[day])))

HomeworkList[PersonNames][WeekDays] = int(input("Total minutes for %s, on %s \n>" % (PersonNames[people],WeekDays[day])))
TypeError: list indices must be integers or slices, not list

whenever I try to run this code I get this error, for example I input the number 30 and it errors out, I am new to Python may someone help

You need to slice by an integer value, currently you are putting the entire list of PersonNames and WeekDays in your slice. people and day are type int.

Your loop should be:

for people in range(len(PersonNames)):
    for day in range(len(WeekDays)):
        HomeworkList[people][day] = int(input("Total minutes for %s, on %s \n>" % (PersonNames[people], WeekDays[day])))

Python typeerror: list indices must be integers or slices, not str Solution, The error “typeerror: list indices must be integers or slices, not str” is raised when you try to access a list using string values instead of an integer. To solve this problem, make sure that you access a list using an index number. The variable mean_data is a nested list, in Python accessing a nested list cannot be done by multi-dimensional slicing, i.e.: mean_data[1,2], instead one would write mean_data[1][2]. This is because mean_data[2] is a list.

As the message states, you pass a list instead of an int to a list.

e.g. in this line:

HomeworkList[PersonNames][WeekDays]
type(PersNames) == list
type(WeekDays) == list

You probably want instead is use this

HomeworkList[people][day]
type(people) == int
type(day) == int

To make the difference more clear this is what each statement looks like when you replace the variable with its values:

HomeworkList[["Jack", "Mary", "John"]][["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]]

vs. e.g.

HomeworkList[0][0]

TypeError: list indices must be integers or slices, not str Problem , TypeError: list indices must be integers or slices, not str list Could you try running it please and let me know what you think is the problem. will still be preserved all you are doing is this let say you have a sentence,. List indices must be integers or slices, not Dict I am doing some operations that involves extracting data from a list where every element is a dictionary. Each dictionary contains two key-value pairs which are a string and then an int (i.e {'ID':0, 'Zip Code':9414}), and then a key-value pair where

indexing 'HomeworkList' should be like this below

specifying integers.. HomeworkList[2][3]

or using slices.. HomeworkList[2:3]

List indices must be integers or slices, not str?, +, -)")) for n in operator: if z == operator[n]: print("No valid operator Throwing the error if z == operator[n]: TypeError: list indices must be integers or slices, not str I thought I could put anything into a list, like a string or an integer, or a Even though strings in Python don't have an iterable method, they� “TypeError: ‘nonetype’ object is not callable” occurs when you try to call a None value as if it were a function. » MORE: Python typeerror: list indices must be integers or slices, not str Solution

TypeError: list indices must be integers or slices, not str, typeerror: list indices must be integers or slices, not str, This type error But if this variable does not have an integer value and instead has a string value, you To better understand this error, let's take a very simple example as 0 i = 0 # Inilised empty string string1 = '' # Run While loop to list length while i� TypeError: string indices must be integer // work with JSON as dict in python Okay, so I've been banging my head on this for the last 2 days, with no real progress. I am a beginner with python and coding in general, but this is the first issue I haven't been able to solve myself.

How to resolve "TypeError: list indices must be integers, not str", and upon running i get this error message: "year1 = data['form']['fiscalyear_id'] TypeError: list indices must be integers, not str" i tried to cast� To solve this error, only use integers to access items from an indexed object like a string or a list. list indices must be integers or slices, not str Like strings, lists are indexed from zero.

Non-English characters are not printed correctly if BeautifulSoup cannot autodetect the encoding. Usually, BeautifulSoup is very good at the autodetecting document’s encoding. BeautifulSoup uses a sub-library called "Unicode, Dammit" to detect a document’s encoding and convert it to Unicode. However, if you know the document's encoding, you

Comments
  • Please share the entire error message. What do/don’t you understand from the error?
  • HomeworkList[PersonNames][WeekDays] Those are lists and can't be indexes. Did you mean HomeworkList[people][day]?