Python Forum
Type Error: Unsupported Operand
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Type Error: Unsupported Operand
#1
Greetings! I am new to this group and apologize in advance if I'm not asking for help properly.

I'm trying to figure out this error:

TypeError: unsupported operand type(s) for -: 'int' and 'list'

For this part of the code:
i = 0.0
for field in val_group_fields:
mprop = [float(sumdict[field]) / (float(sumdict["Total"]))]
i+= mprop * (1 - mprop)
sumdict[field] = [sumdict[field], mprop]

The error happens because of the + and – operators for the mprop list. It looks like mprop is either an integer or list and they cannot be added or subtracted together. I think I have to change them to work, but I can’t figure out how to do that. Please assist. Thank you!
Reply
#2
Greetings and felicitations!

Why not show us what val_group_fields and sumdict look like? Maybe also explain exactly what you wish to achieve?

You can't add an integer to a list.
You can append an integer to a list. Is that what you want to do?
You can remove an element from a list. Is that what you want to do?
You can add a list to a list. Is that what you want to do?
You can divide an integer by a floating point number and vice-versa.

field is presumably an integer.

Quote:sumdict[field]) / (sumdict["Total"]

will give a number, probably not an integer, probably less than 1.

I can't see what this is for:

Quote:i+= mprop * (1 - mprop)

What should it achieve?
Reply
#3
Thank you very much, Pedroski55! I will give this a try and comment back any additional errors as a result.

Kind regards,
jhancock
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Wrong type error rowan_bradley 6 1,232 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 9,335 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 2,177 May-07-2022, 08:40 AM
Last Post: ibreeden
  unsupported operand type(s) for %: 'list' and 'int' RandomCoder 4 32,896 May-07-2022, 08:07 AM
Last Post: menator01
  Python Anytree - Is not of type 'NodeMixin' error georgebijum 3 2,098 May-05-2022, 01:43 PM
Last Post: Gribouillis
  Incorrect Type Error milkycow 4 2,918 Jun-25-2021, 06:04 AM
Last Post: milkycow
Star Type Error: 'in' object is not callable nman52 3 3,418 May-01-2021, 11:03 PM
Last Post: nman52
  Error : "can't multiply sequence by non-int of type 'float' " Ala 3 3,098 Apr-13-2021, 10:33 AM
Last Post: deanhystad
  Type Error in Python MarcusB 3 2,579 Mar-30-2021, 06:34 PM
Last Post: buran
  unsupported operand type(s) for /: 'str' and 'int' Error for boxplot soft 1 3,071 Feb-09-2021, 05:40 PM
Last Post: soft

Forum Jump:

User Panel Messages

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