Differences between vector, set, and tuple

后端 未结 7 587
庸人自扰
庸人自扰 2021-01-30 17:15

What are the differences between vectors, sets, and tuples in programming?

7条回答
  •  滥情空心
    2021-01-30 17:53

    Mathematically

    A tuple has properties that distinguish it from a set.

    • A tuple may contain multiple instances of the same element, so tuple (1,2,2,3) != (1,2,3) but set {1,2,2,3} = {1,2,3}.
    • Tuple elements are ordered: tuple (1,2,3) != (3,2,1), but set {1,2,3} = {3,2,1}.
    • A tuple has a finite number of elements, while a set or a multiset may have an infinite number of elements.

    Vector is a different type represented by multiple tuples.

    Cheers :-)

提交回复
热议问题