Subtraction of one list of lists from another list of lists

Ibe

I want to subtract a list of lists from corresponding elements of another list of lists such as:

a = [[1, 2], [3, 4]]
b = [[1, 2], [3, 0]]

with expected output to be:

c = [[0, 0], [0, 4]]

Subtraction with only one list from another is easy with:

c = [i - j for i, j in zip(a, b)]

but this isn't working for a list of lists and returns TypeError: unsupported operand type(s) for -: 'list' and 'list'. Any ideas on how to do it?

Lord Henry Wotton

This should do the job:

c = [list(map(lambda x, y: x - y, ii, jj)) for ii, jj in zip(a, b)]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Subtraction of one list of lists from another list of lists

From Dev

How to compare one value from a list of lists to another value from a list of lists in Python

From Dev

Python List Comprehension: Affix strings from one list to the start of strings in another, for a list of lists

From Dev

find lists that start with items from another list

From Dev

Two Combination Lists from One List

From Dev

Python - sort one list from two lists

From Dev

Converting list of lists to one list

From Dev

split dictionary into two lists , one list is for key, another list is for value

From Dev

Generate lists from a list

From Dev

Remove list values from a column of lists based on another list

From Dev

Create a list from two lists based on values in another list

From Dev

Assigning a list to another list in a list of lists in Python

From Dev

Referencing a list from list of lists

From Dev

Python build one dictionary from a list of keys, and a list of lists of values

From Dev

Apply the order of list to another lists

From Dev

trouble appending lists to another list

From Dev

Modifying lists using another list

From Dev

Copying a list of lists into part of another one in the most pythonic way

From Dev

How to sort a list of lists by one element ascending and another descending

From Dev

How to assign a number from a list of lists to another list of lists in python 3?

From Java

How to concatenate lists into one list

From Dev

convert a tuple of lists, into one list

From Dev

Comparing one element in a list of lists

From Dev

How to concatenate lists into one list

From Dev

convert a tuple of lists, into one list

From Dev

List sorting - two lists into one

From Dev

Pandas Series of lists from list of lists

From Dev

Select a subset of lists from list of lists

From Dev

How to extract lists from a list of lists

Related Related

  1. 1

    Subtraction of one list of lists from another list of lists

  2. 2

    How to compare one value from a list of lists to another value from a list of lists in Python

  3. 3

    Python List Comprehension: Affix strings from one list to the start of strings in another, for a list of lists

  4. 4

    find lists that start with items from another list

  5. 5

    Two Combination Lists from One List

  6. 6

    Python - sort one list from two lists

  7. 7

    Converting list of lists to one list

  8. 8

    split dictionary into two lists , one list is for key, another list is for value

  9. 9

    Generate lists from a list

  10. 10

    Remove list values from a column of lists based on another list

  11. 11

    Create a list from two lists based on values in another list

  12. 12

    Assigning a list to another list in a list of lists in Python

  13. 13

    Referencing a list from list of lists

  14. 14

    Python build one dictionary from a list of keys, and a list of lists of values

  15. 15

    Apply the order of list to another lists

  16. 16

    trouble appending lists to another list

  17. 17

    Modifying lists using another list

  18. 18

    Copying a list of lists into part of another one in the most pythonic way

  19. 19

    How to sort a list of lists by one element ascending and another descending

  20. 20

    How to assign a number from a list of lists to another list of lists in python 3?

  21. 21

    How to concatenate lists into one list

  22. 22

    convert a tuple of lists, into one list

  23. 23

    Comparing one element in a list of lists

  24. 24

    How to concatenate lists into one list

  25. 25

    convert a tuple of lists, into one list

  26. 26

    List sorting - two lists into one

  27. 27

    Pandas Series of lists from list of lists

  28. 28

    Select a subset of lists from list of lists

  29. 29

    How to extract lists from a list of lists

HotTag

Archive