Python Tips and Tricks: 4 Ways to Compare Lists

Поделиться
HTML-код
  • Опубликовано: 21 окт 2024

Комментарии • 4

  • @aaronrock9534
    @aaronrock9534 2 года назад +1

    0:23 Identity Matters
    Use 'is' operator to check if the object references point to the same object in stored in memory.
    1:40 Order and Duplicates Matter
    Use '==' operator to check the index of each list refers to the same object.
    *Assumes objects in the list can be compared using equality.
    3:48 Order Ignored, Duplicates Matter
    from collections import Counter. Counter creates a counter object that is a dictionary. It contains unique objects as the key and the number of times it occurs is that value. From here, you can compare the two Counter objects using '==' operator.
    *Assumes objects in the list are hashable and supports equality
    6:46 Order Ignored, Duplicates Ignored
    Convert each list to a set. Sets only contain unique objects. Use '==' operator to compare the sets to check if the lists contain the same objects, ignoring the order and quantity of each object.
    *Assumes objects in the list are hashable and supports equality.

  • @gorpazin6982
    @gorpazin6982 2 года назад

    Thanks for this video.

  • @D_DailyTips
    @D_DailyTips Год назад

    How to compare sublists of two list
    A=[[1,2,3],[1,3,5]]
    B=[[1,2,3],[1,6,2]]