Python Forum
Trouble with converting list , dict to int values!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble with converting list , dict to int values!
#6
I'm not sure if you could pack in any more errors into such a short line of code.
diff = abs (x(1)-(2))
Start with x is a list. You cannot do x(). You can do x[]. x[1] is a dictionary.
diff = abs (x[1]-(2))
Now (2) is the number 2. So this tries to subtract the number 2 from a dictionary. That is not allowed. I am going to assume you want to subtract the X number in dictionary x[1] from the X number in dictionary x[2]
diff = abs (x[1]- x[2])
This is closer but still wring because it subtracts a dictionary from a dictionary and you want to subtract the 'X' attributes.
diff = abs (x[1].X- x[2].X)
There is probably a reason you are using a list of dictionaries that is not discussed in your post instead of just putting the numbers in the list like this.
x = [2593.75, 2457.42, 2593.75, 2457.42]
Reply


Messages In This Thread
RE: Trouble with converting list , dict to int values! - by deanhystad - Sep-03-2020, 12:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting column of values into muliple columns of counts highland44 0 261 Feb-01-2024, 12:48 AM
Last Post: highland44
  Copying the order of another list with identical values gohanhango 7 1,172 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,266 Nov-03-2023, 05:35 PM
Last Post: huzzug
  trouble reading string/module from excel as a list popular_dog 0 433 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  Comparing List values to get indexes Edward_ 7 1,190 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Adding values with reduce() function from the list of tuples kinimod 10 2,682 Jan-24-2023, 08:22 AM
Last Post: perfringo
  user input values into list of lists tauros73 3 1,079 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  Membership test for an element in a list that is a dict value for a particular key? Mark17 2 1,229 Jul-01-2022, 10:52 PM
Last Post: Pedroski55
  Are list/dict comprehensions interpreted really sequentially? anata2047 3 1,468 May-31-2022, 08:43 PM
Last Post: Gribouillis
  dict class override: how access parent values? Andrey 1 1,648 Mar-06-2022, 10:49 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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