Post

PythonPython

H
Harish Harsh

Posted on 24th April 2024|35 views

0
votes

Python Subtract Lists

How to subtract two lists in python?

Answers
P
James ROBERT

Posted on 24th April 2024

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