logo-MindMajix
PostPythonPython
H
Harish Harsh

Posted on 24th July 2024|40 views

0
votes

Python Subtract Lists

How to subtract two lists in python?

1 answers
Answers
P
James ROBERT

Posted on 24th July 2024| views

It is very simple to subtract two lists, just follow this example

li1 = [3, 3, 3]

li2 = [2, 2, 2]

result = []

zip_object = zip(li1, li2)

for li1_i, li2_i in zip_object:

   result.append(li1_i-li2_i)

print(result)

Output:

[1, 1, 1]

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number