Comparing two lists and only printing the differences? (XORing two lists)

前端 未结 6 1768
盖世英雄少女心
盖世英雄少女心 2020-12-09 11:55

I\'m trying to create a function that takes in 2 lists and returns the list that only has the differences of the two lists.

Example:

a = [1,2,5,7,9]         


        
6条回答
  •  我在风中等你
    2020-12-09 12:53

    Note: This is really unpythonic and should only be used as a homework answer :)

    After you have sorted both lists, you can find duplicates by doing the following:

    1) Place iterators at the start of A and B

    2) If Aitr is greater than Bitr, advance Bitr after placing Bitr's value in the return list

    3) Else if Bitr is greater than Aitr, advance Aiter after placing Aitr's value in the return list

    4) Else you have found a duplicate, advance Aitr and Bitr

提交回复
热议问题