Can anyone help me with this error TypeError list indices must be integers or slices not str

+1 vote
def format_response(coviddata):

        country = coviddata['country']

        cases = coviddata['cases']

        todayCases=coviddata['todayCases']

        deaths=coviddata['deaths']

        todayDeaths=coviddata['todayDeaths']

        recovered=coviddata['recovered']

        active=coviddata['active']

        critical=coviddata['critical']

        casesPerOneMillion=coviddata['casesPerOneMillion']

        deathsPerOneMillion=coviddata['deathsPerOneMillion']

        totalTests=coviddata['totalTests']

        testsPerOneMillion=coviddata['testsPerOneMillion']

        final_str = "country: {} \n,cases: {} \n,todayCases: {} \n, deaths :{} \n, todayDeaths:{}\n ,recovered :{} \n, active:{} \n, critical : {} \n, casesPerOneMillion : {} \n ,deathsPerOneMillion: {} \n ,totalTests :{} \n ,testsPerOneMillion:{} ".format(country,cases,todayCases,deaths,todayDeaths,recovered,active,critical,casesPerOneMillion,deathsPerOneMillion,totalTests,testsPerOneMillion)

        return final_str
Nov 5, 2020 in Python by varshasp
• 130 points

edited Nov 5, 2020 by Gitika 2,372 views

1 answer to this question.

0 votes
Hi, @Varshap

 It’s a TypeError, which tells us that we are trying to perform an operation on a value whose type is not compatible with the operation.

To solve this problem, make sure that you access a list using an index number.
answered Nov 5, 2020 by anonymous
• 65,770 points

Related Questions In Python

0 votes
1 answer

TypeError: list indices must be integers or slices, not str

Hi@akhtar, As we know that the index of ...READ MORE

answered Oct 15, 2020 in Python by MD
• 95,460 points
13,730 views
0 votes
3 answers
0 votes
1 answer

Python error "TypeError: string indices must be integers, not str"

Hey @Dipti email_s.append(email_1["email_address"]) This is the list on ...READ MORE

answered Jul 5, 2019 in Python by Jinu
22,972 views
0 votes
0 answers

TypeError: tuple indices must be integers or slices, not tuple

Traceback (most recent call last):   File "main.py", line ...READ MORE

Aug 25, 2020 in Python by Peddabudi srikanth
• 120 points
4,643 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,464 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,125 views
0 votes
1 answer

i am getting this error "TypeError: tuple indices must be integers or slices, not Database"

Hi, @Shabaj, Regarding your query, I hope this ...READ MORE

answered Dec 10, 2020 in Python by Gitika
• 65,770 points
1,196 views
0 votes
1 answer

Can anyone explain me this error?

It is an Indentation error. There should be ...READ MORE

answered Oct 14, 2020 in Python by Gitika
• 65,770 points
686 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP