Python Forum
Subtracting Elements of a Sublist in Python 3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subtracting Elements of a Sublist in Python 3
#1
Hello,

I am having an issue with subtracting sublists. With the given sublist:

first_list: [[0, 1], [2,4], [8,7]]

There is supposed to be a new list where that contains the difference of the first element from the second element in the sublist:

[-1,-2,-1]

This is the code so far:

for sub_list in data:
differences.append((int(sub_list[1]))-(int(sub_list[0])) in data)

I tried to run this with the other part of the problem to multiply the resulting list, but it fails. It seems to be not iterating. Can anyone offer some suggestions?
Reply


Messages In This Thread
Subtracting Elements of a Sublist in Python 3 - by pangloss3030 - Dec-25-2020, 08:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Repeating elements when appending in iteration in Python 3.6 miguelsantana 2 3,476 Dec-17-2017, 01:22 AM
Last Post: Terafy

Forum Jump:

User Panel Messages

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